IntelliJ Java IDE
The moose likes Threads and Synchronization and the fly likes Keeping a sub-thread alive Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Keeping a sub-thread alive" Watch "Keeping a sub-thread alive" New topic
Author

Keeping a sub-thread alive

sidhu singh
Greenhorn

Joined: Jun 18, 2003
Posts: 1
I am creating a new thread inside my main thread. How can I keep this new thread alive for ever or for that matter for some limited time (even efter it finishes the processing)?
main{
.
.
new thread(); // keeping this thread alive
// even after it finishes processing
.
.
}
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
The new thread will keep running (assuming you are running a loop inside it) after the main thread finishes. This is the default behavior. In fact, if you DONT want the thread to continue running after main() exits, you must explicitly set the thread to be a daemon thread before you start it.
So you don't have to do anything special to get the behavior you want. Try a simple example for yourself and see!


Rob
SCJP 1.4
 
 
subject: Keeping a sub-thread alive
 
Threads others viewed
Threads
thread again
Daemon Thread
About the join() method
Q. Methods of a dead thread.
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com