Trying to terminate number of threads ...

Hi,
I am developing an application for a distributed system. Briefly, there are 8 nodes which exchange messages according to a fixed topology. I invoke the application 8 times, one for each node. The application has a main thread that handles sending messages to other nodes. I spawn another thread to handle receiving messages from other nodes.
There is a limit of the number of messages sent and received. My problem is that, once the limit has reached, I want the receiving thread to terminate so that the application ends in a normal fashion. I am able to arrive at the condition where all the messages are being sent and received properly. However the application doesn't exit because the threads are still alive. When I forcibly close the application (Ctrl+C), I get SocketException because I am breaking the socket connection.
I want to implement it something like this... All the nodes upon completion send a "finish" signal to the initiator node (typically, node 0). Upon receiving all "finish" messages, the initiator node will send "terminate" message to all the nodes.
But the problem is the topology is such that all the nodes are not connected to each other. some of the nodes may not be connected to each other at all. In that case, how can the node that is not connected to the initiator node, send a "finish" message?
Any ideas please?
Tangi
PS: I will include the source code if required.

I have posted the question again over here because I was not getting any response (it was an old question of mine that I continued today).
I have no clue how to work with the join() method. Can u share anything that you know about join()? I mean, where to add? What does it do?
Thank you

Similar Messages

  • How to terminate a java thread from c++ code?

    Hi,
    I made a screensaver which loads a jvm, forks a thread running a java class, wait until user's action(i.e. mouse move/click keyboard input), then terminate the java thread.
    However, I met a problem, How to terminate a running java thread from c++ code?
    Here is my code, but it does not work: (even after the terminate is called, jvm throws an error)
    JNIEnv* env;
    JavaVM* jvm;
    HANDLE hThread; //handle for the startThread
    unsigned __stdcall startThread(void *arg)
         jclass cls;
         jmethodID mainId;
         jint          res;
         int threadNum = (int)arg;
         res = jvm->AttachCurrentThread((void**)&env, NULL);
    cls = env->FindClass( MAIN_CLASS);
         mainId = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
         // setup the parameters to pass to main()
         jstring str;
         jobjectArray args;
         int i=0;
         args = env->NewObjectArray(1, env->FindClass("java/lang/String"), 0); //only one input parameters
         str = env->NewStringUTF("localhost");
         env->SetObjectArrayElement(args, 0, str);
         env->CallStaticVoidMethod(cls, mainId, args); // call main()      
         if (env->ExceptionOccurred()) {
                   env->ExceptionDescribe();
         return TRUE;
    Here is the main method:
    First create the jvm and load the thread. then tries to terminate the thread, but failed here
    switch (msg)
    { case WM_CREATE:
              JavaVMOption options[NUMBEROFOPTIONS];
              JavaVMInitArgs vmargs;     
              jint rc;
              vmargs.version = JNI_VERSION_1_4; /* version 1.4 */
              vmargs.options = options;
              vmargs.nOptions = NUMBEROFOPTIONS;
              vmargs.ignoreUnrecognized = JNI_FALSE;          
              rc=JNI_CreateJavaVM( &jvm, (void **)&env, &vmargs ); /* create JVM */
              /* We pass the thread number as the argument to the invoked thread */
              unsigned int threadId = -1;
              // to initialize a thread-safe C runtime library
              hThread = (HANDLE)_beginthreadex(NULL, 0, &startThread, NULL, 0, &threadId );
    } break;
    case (WM_DESTROY):
              CloseHandle( hThread );
              jvm->DestroyJavaVM(); /* kill JVM */
              Debug("Destroy Java Virtual Machine\n");
    }break;
    Note, after the thread "startThread" runs, it has an infinite loop and will not terminate, until the user clicks to terminate.(I didn't call jvm->DetachCurrentThread();_endthreadex(0); in the "startThread" because the java thread will not terminate by itself)
    Thus, the only way to terminate the thread is to call closehandle(hthread) in the main thread, which may cause jvm to throw an error.
    Do you know how to terminate a java thread safely???
    Thanks a lot

    Assuming that your java thread is in a loop of some kind. Such as
    int i=1; /* I tried using a boolean, I just could not get my C++ env, to change this value. So i decided to use an int */
    run {
    while(i)
    isdfjsdfj
    void seti()
    i=0
    So, B/4, i call destroyVM in my C++ code, i call this seti(). so the loop terminates, therefore my thread finishes executing and ends.
    Hope this helps
    tola.

  • High number of threads and high CPU usage on a single instance

    Without any apparent reason, in some moments of day the website reports an increment of the HTTP Queue Length from an average of 10/20 queued requests to 100/200 and more.
    In that period of time the Average Response Time increases but the number of the requests on the website don't. Even increasing the instances it doesn't help to resolve the problem (maybe it just reduced it).
    It seems that the problem is not related to the traffic on the site. This issue happens either when the traffic is high or low.
    The autoscaling works well, we don't have peak of traffic but always a slow increasing of requests and the CPU is always below the 50% (memory too). The issue is resolved by the swap of the site and sometimes it's resolve by itself after a while.
    What I discovered when the issue happens, is that there's an instance (just an instance only), that has an high number of threads and CPU usage on the W3WP.exe process and these values are above the mean than the other instances. Eg, instances are around
    50/60 threads and 10/20% of CPU, the instance with the problem has 200 threads and 50/60% of CPU. If I kill the W3WP process on that instance the issue is resolved. 
    I monitored the HTTP requests, I tried the website extension "Diagnostics as service" but I can't discover anything that can help me to understand the problem. Of course, there are many requests that go in timeout but it is a consequences of a
    unresponsive instance.
    On the web hosting plan there are only two sites: the production site and its staging which is used for update of the production only and it's always sleeping. Plus, no webjobs are running on this site.
    What can I do to gather useful information that can help me to understand the reason of this problem?
    Thank you!

    "Does the instance with the high counts receive more traffic than the other instances? Is it possible that the load balancer not
    working the way it should be?"
    How can I get that information? I can't see metrics for a specific instance
    "Does it always happen to the first instance?"
    I will check it better, but in the order given by the Processes panel it's the second instance which has the issue. The scaling is at 2 instances for the most part of the time (it's the minimum).
    Maybe one time it was the 3th instance but I'm not sure, I'll give it more attention.
    " How long do these moment last?"
    The time can be 10 to 30 minutes, but I fix it as soon as I see the problem. It's not the down-scaling to resolve it because in these situations the CPU as well is high so the scaling holds or increases the number of instances.
    "- How often do these moments occurs?"
    It occurs quite often, 2/4 times a week.

  • Grey screen and "incorrect number of thread records"

    I think I am in trouble. My eMac will not boot and gets stuck on the great screen with the Apple logo and the spinning windmill. I have followed the instructions in the Apple help article up to but not including "archive and install". I tried the advanced secure boot and the messages I got over and over were "HFSSWAPHFSPlusBTIternalmode: catalog record #30 keylength=34 expected=144 node=15278 File ID=4 volume= Macintosh HD device=/dev/disk 0s 10"
    And
    "Jan31 12:00:35 Launched: /System /Library/CoreServices/Loginwindow.app/Contents/MacOS/Loginwindow Port/dev/console exited abnormally: Trace/ BPT trap"
    And
    Jan31 12:02:13 Launched: Getty repeating too quickly on port/ dev/ console, sleeping"
    I rest the PRAM and NVRAm as instructed.
    I booted from the OSX 10.4 install disk and ran the verify disk and repair disk sequences several times. It did repair a number of things but it kept coming back to "
    Message was edited by: Mont Rigaud Stud
    Itkept coming back to "incorrect number of thread records". Even after running repair disk again several times it came back to the same thing and said
    "the volume Macintosh HD could not br repaired after 3 attempts
    ERROR: the underlying task reported failure On exit
    1HFS volume checked
    1 vOlume could not be repaired because of an error
    Repair attempted on 1 volume
    1 volume could not be repaired"
    What should I do? I am NOT BACKED UP! How do I back up now? Can I usean external Hard drive? I really do not want to lose my photOs, email and business files.
    I am typing my question on my iPhone, so that accounts for the poor capitalization.
    Thanks
    Doug

    Will it boot in Safe Mode? See
    What is Safe Boot, Safe Mode? (Mac OS X)
    http://docs.info.apple.com/article.html?artnum=107392
    Takes a while to run, but it usually "fixes" problems.
    Resolve startup issues and perform disk maintenance with Disk Utility and fsck
    http://docs.info.apple.com/article.html?artnum=106214
     Cheers, Tom

  • Max Number of threads per Process in Solaris 8

    I'm running into qpplication which crashes with a segfault when the LWP for that process hits about 255, i'm trying to find the maximum number of threads per process using sysconf and its returning -1
    #include <unistd.h>
    int
    main(void)
    printf("%ld\n",sysconf(_SC_THREAD_THREADS_MAX));
    return 0;
    I'm using gcc 3.3.2
    If anyone can tell me the maximum number of threads per process I would really appreicate it.
    Also the maximum number of open files per process.
    Thanks in advance
    - Rodrick Brown
    - DoITT

    Please make sure that you build a
    multithreaded program first (check with ldd).
    If anyone can tell me the maximum number of threads per process I would
    really appreicate it.
    Also the maximum number of open files per process. It depends on the architecture (x86/SPARC), OS version,
    64 or 32-bit, /etc/system, shell limitations (/usr/bin/ulimit) ...
    Search for "rlim_fd_max / rlim_fd_cur" on docs.sun.com too.
    HTH,
    -vladimir

  • Number of threads for imap process

    What is the resonable nimber of threads for imap procerss?
    I have 2 impad procrss and number of threads more then 200!!!
    I think this is to much for 700-900 concurrent impa connection&
    What is the reasons for this big number

    Actually, your configuration sounds pretty close to correct for your load.
    We allocate up to 250 threads, as many clients connect more than one time per session, and open more than one folder at a time.
    I would not mess with the number of threads.
    If most of your users have small numbers of messages and folders, you may be able to get away with a single imap process, but if you have several processors, two is fine, too.
    Is there a problem or error situation you're trying to work around? What exact version of Messaging do you use? (imsimta version gets that)

  • Limiting the number of threads that are created

    I am trying to write a web crawler as a way of learning about multi-threading and I have hit a stumbling block (probably my design). The way the application I have started works is that I provide a single URL, which is passed to a thread and that thread then parses the web page building a list of links (If the links are not already held in a 'visited' list then they are saved in a list in the Runnable object that is parsing the html page).
    When the page has been parsed the list of links are then passed to a method in a Utilities class that creates a new group of threads, 1 for each link and each of these threads then does the same thing. The problem I have is that as more and more links are captured more and more threads are created eventually I either get a out of memory exception or I get an operating system 'cannot create native thread' message. I am not sure if the threads are staying in memory after they have done their tasks, I am not sure why I am running out of memory so quickly.
    What I would like to try and do is to set a limit for the maximum number of threads created and then only create new threads if the limit is not breached. If someone could point me in the right direction that would be good, I have googled around but cant find an example of what I want to do.
    Thanks

    Thanks for that, that has given me a lot to read up on and I can already see where I went wrong.... I think implementing a thread pool and also a work queue is probably the way I will go from now on.

  • Macbook Air froze/turned it off to restart.  Now it won't restart it goes to Gray screen with apple like it is loading, but when gets to the end it turns off.  Try repairing it states incorrect number of thread records.Volume Macintosh HD found corrupt

    Macbook Air froze/turned it off to restart.  Will not restart just goes to gray screen like it is reloading and then shuts off.  Have tried everything.  When trying to reapir it says incorrect number of thread records, should be 108456 instead of 108455.  Invalid voume directory count/the volumbe macintosh HD was found corrupt and needs to be repaired.  How do I repair it?

    Hello cgstephen
    You would need to contact Apple or an Apple Authorized Service provider by checking out the page below. It will have everything you need to know about setting your MacBook Air up to get it repaired.
    Service Answer Center - Mac notebooks
    http://support.apple.com/kb/index?page=servicefaq&geo=United_States&product=Macn otebooks
    Regards,
    -Norm G.

  • Trying to terminate lines

    Customer (removed) in Denver.  I've been trying to terminate two lines that I don't want or need (the last 4 digits of the two lines that are not under contract and are not prepaid removed)
    I've been told 3 times now that the lines can be terminated  immediately and 4 times that they can't before the 23rd of August.  The last person to say it's "impossible" said "not unless there is a death in the family".  And also that there is nothing he can do because it's just their policy; contradicting online chat with a Verizon employee and recordings of 3 others saying of course it can be done.
    I have around a good 35 to 45 minutes of recordings (minus all the hold times) talking with Verizon customer service and someone in sales, being told one thing then another.  A complete run around.  Once while asking for a corporate number got me sham number to get a prepaid gift card in the mail if I agree to first pay $2.00.   That person then, when I asked again for a supervisor again, hung up on me.
    When I can pay off the edge plan rip-off I was misled about, I'll be ending that line as well and my relationship with Verizon.
    Social media and other websites are going to LOVE hearing the run-around I've been given.
    If I have to keep the lines until the 23rd and my bill is not prorated (I have Laila--sp?-- in sales as the last one telling me that they can do it and should) then I will see to it that everyone I know and have any influence with never gives Verizon any extra business as soon as they can get away from your traps.
    And ALL that I have collected and recorded is going up on the web and social media.
    You don't care about customer service and a positive experience.  Only getting the last cent out of someone especially when you believe they really are going to leave because of your horrible policies.
    Before who ever's responsibility it is to delete these truthful messages... you might want to take note of this.  Verizon will see and hear much more about it before we are finished.
    >> Subject edited for brevity and personal information removed to comply with the Verizon Wireless Terms of Service <<
    Message was edited by: Verizon Moderator

    I have posted the question again over here because I was not getting any response (it was an old question of mine that I continued today).
    I have no clue how to work with the join() method. Can u share anything that you know about join()? I mean, where to add? What does it do?
    Thank you

  • HT4528 My friend switched from an iphone to a non apple phone. All my texts to him in groups and one on one still come up as imessages. How do I get rid of the imessage when i talk to him? I have tried deleting his number, deleting all messages he was apa

    My friend switched from an iphone to a non apple phone. All my texts to him in groups and one on one still come up as imessages. How do I get rid of the imessage when i talk to him? I have tried deleting his number, deleting all messages he was apart of

    Did you try to unregister the phone?
    Check this discussion

  • Safari 5.0.6 repeatedly crashes.  MacBook Pro 10.5.8  I've emptied cache and reset to no avail.  I've tried solutions found in other threads.  Help, please.

    Safari 5.0.6 repeatedly crashes.  MacBook Pro 10.5.8  I've emptied cache and reset to no avail.  I've tried solutions found in other threads but the more advanced don't seem to apply to me. Help, please.

    Not sure what other tests they could run for me. I've pretty much run all the tests I can using Drive Genius and Tech Tool Pro 5. Is there anything they use that I don't know about??

  • How to find out the number of threads created under java vm at runtime

    our application seems to have hit the max number of threads that can be created under vm and the vm will just hang after that. that behavior seems to be consistent from an article that I read earlier.
    I wonder any way that java app can find out the number of threads currently created under vm?
    thanks in advance!

    If you are not starting an extra thread group you can use the Thread.activeCount method. But this willnot return all the threads, as there are some jvm threads, i.e. garbage collector. Also if you are running on a Unix type operating system then you can send a signal to the jvm to give you a thread dump, i think the signal is sighup.
    If the application is hanging i would of thought that you have a deadlock situation rather then the JVM not being able to create new threads, roughly how many threads should be running ??

  • I have Photoshop and Elements 9, and im getting a new computer. I would like to put them on the new one. I tried my serial number but it didnt work.

    I have Photoshop and Elements 9, and im getting a new computer. I would like to put them on the new one. I tried my serial number but it didnt work. I dont know what to do?

    Error "The serial number is not valid for this product" | Creative Suite

  • I have Windows XP, 32 bit version 2002 Svc Pack 2 and when trying to download iTunes 10.5 I am getting the following "The older version of Bonjour cannot be removed.  Contact your tech."  I've tried a good number of remedies to no avail.  Can anyone help?

    I have Windows XP, 32 bit version 2002 Svc Pack 2 and when trying to download iTunes 10.5.1 I am getting the following "The older version of Bonjour cannot be removed.  Contact your technical support."  I've tried a good number of remedies to no avail.  Can anyone help?

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down the page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    If you are running 64-bit Windows and the above steps haven't helped try installing the version of iTunes that can be downloaded from this support document. iTunes 12.1 for Windows (64-bit — for older video cards)
    If you still have no luck try reinstalling iTunes 12.0, links in the user tip.
    tt2

  • Hi my iphone was fully charged and turned its self off, i have tried to turn it back on and reset it, but no luck so i have plugged it in to my pc and it displays the apple logo and then goes back off i have tried this a number of times with no success

    hi my iphone was fully charged and turned its self off, i have tried to turn it back on and reset it, but no luck so i have plugged it in to my pc and it displays the apple logo and then goes back off i have tried this a number of times with no success anyone got any idears?

    Try here:
    iOS: Not responding or does not turn on

Maybe you are looking for

  • Plz help don't know how to create a query and link it to a UDF

    hi, i am new to business one and however hard i am trying to use a query to link it to a UDF, it is not working. i think i am doing the whole thing wrong,so ill just post one problem i have and if any one of u can explain to me in steps i may be able

  • Cannot sync ipod to vista

    I am having 3 problems - 1. my ipod does not show as a device in itunes 2. the synch ipod selection in file is greyed out 3. the computer will not recognize my USB cable. I have tried reloading 7.3, buying new USB cables, using different ports and al

  • Collaboration in obiee 11g

    Hi every one, Recently i came across term collaboration in obiee 11g. I searched for it and could not find any information on it. Is it a new feature in obiee 11g or some thing else? If any one have any additional information or links where i can fin

  • Stopping a process remotely

    Dear, Is there a way to stop a process, if we know the GUID, using a webservice? Regards, Frederik-Jan

  • Adobe CS6 Design Standard: NO BRIDGE?

    I just installed the CS6 Design Standard for Students on my Mac. While Adobe Bridge is an additional listed component it is not installed with the rest of the suite (even though the media encoder was) and I cannot locate it on the installation disk.