• 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

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).]
 
This tiny ad is guaranteed to be gluten free.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic