• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Threads

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does a thread continue to run when the program exits the main() method?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Frank,
Even if the control comes/exits out of the main method, the thread continues to run. As it is main method itself is a seperate thread in Java. Only if u call the exit method explicitly as below, the thread will stop running (All the threads initiated by the program will stop).
<code><pre>public class ThreadRun implements Runnable
{
public void run()
{
for( ; ; )
{
System.out.println("Thread Running");
}
}
public static void main(String a[])
{
Thread t = new Thread( new ThreadRun());
t.start();
System.exit(0);
}
}</pre></code>

[This message has been edited by Jim Yingst (edited February 19, 2000).]
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic