Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Keeping a sub-thread alive

 
sidhu singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!