Results 1 to 4 of 4
  1. #1
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default Stop multithreads at same time

    Hi All,
    Nice to be here after a long time.

    I had a question, simple one but still is eating up my head.

    Condition is "Suppose if 15 threads are running and due to some condition i will have to shutdown jvm and before that i want to stop all the threads."

    Can anyone tell me which methos is feasible to use in this condition and how?

    Waiting for reply from all the giants here like Eranga and all..
    To finish sooner, take your own time....
    Nivedithaaaa

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

  3. #3
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Its opening the same link as this one.....

    Kidding of me is it??? :rolleyes:
    To finish sooner, take your own time....
    Nivedithaaaa

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    DB is trying to tell you that you posted the same question twice. Please close the other one.

    If you have a bunch of threads running and you want to shut down the JVM, you have several options.

    Worst: System.exit(0); will stop the JVM

    Second worst: Set each thread as daemon. When the main threads ends, the JVM will shut down.

    Best: Keep track of all your threads in an ArrayList object. Place a flag in each Runnable a thread uses, make the flag "volatile", and check that flag regularly. At the same time, check Thread.currentThread().isInterruped(). Set the flag if Thread.sleep() is interrupted. Exit the run() method when the flag is set or the thread is interrupted.

    When you want to shutdown, set the flag of each thread's Runnable. If the thread blocks for extended periods, such as waiting on a socket, you may need to wait a second or so, and then interrupt any threads that did not end when the flag was set.

Similar Threads

  1. [SOLVED] Stop multithreads at same time
    By Niveditha in forum Threads and Synchronization
    Replies: 3
    Last Post: 02-25-2009, 05:51 PM
  2. Can you stop a gif? xd
    By Exhonour in forum New To Java
    Replies: 0
    Last Post: 01-16-2009, 09:44 PM
  3. Threads execution stop
    By jyotigupta6 in forum Threads and Synchronization
    Replies: 1
    Last Post: 10-31-2008, 02:41 PM
  4. how to stop a thread
    By willemjav in forum Advanced Java
    Replies: 19
    Last Post: 09-10-2008, 08:11 AM
  5. how to stop refreshing page
    By cecily in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 02:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •