[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Shutting down with Many Threads...

Posted on 2000-05-10
8
Medium Priority
?
199 Views
Last Modified: 2010-04-01
I have a multi-threaded app that I want to shut down but only after all threads have completed.
Is it OK to call System.exit(0); ?
Will this do what I want?
Thanks,
Slinky
0
Comment
Question by:slinky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 2

Accepted Solution

by:
AlexJ030200 earned 150 total points
ID: 2796630
Hi slinky,

System.exit(0) will interrupt all of the non completed threads.

In order to do what you want, you should wait for all of the threads to die.

One simple way to achieve that is to create all of your threads in a new
group and while there are still some
threads alive in the group
(activeGroupCount() in class ThreadGroup), pick anyone (enumerate in
class ThreadGroup) and join it (join() in class thread).

Hope this helps.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2796964
> I want to shut down but only after all threads have completed.

well - the app will stop if all the (non-daemon) Threads have completed :)

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 2796993
> I want to shut down but only after all threads have completed.

well - the app will stop if all the (non-daemon) Threads have completed :)

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:snjkrva
ID: 2798250
Create a ThreadGroup and assign all the thread to it....
before System.exit(0) check whether threads are alive or not....

isAlive() method....for all the threads....u can also check for count...it should be one as main thread...


regards,
sanjeev
0
 

Expert Comment

by:snjkrva
ID: 2798251
Create a ThreadGroup and assign all the thread to it....
before System.exit(0) check whether threads are alive or not....

isAlive() method....for all the threads....u can also check for count...it should be one as main thread...


regards,
sanjeev
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2798635
snjkrva, I don't see how your "answer" is fundamentally different than the comment made by AlexJ long before you joined the topic.
0
 
LVL 1

Author Comment

by:slinky
ID: 2837873
I'll have to reject this as jim_cakalic is right...
0
 
LVL 1

Author Comment

by:slinky
ID: 2837876
Cheers dude...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question