Basic Thread question
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Milind_Nimgaonkar
Posted On:   Wednesday, April 16, 2003 08:37 AM

Hi,


I have a very basic thread question. I have a Servlet that loads on startup and it starts a new thread that is in an
infinite loop. So, if we kill the main JVM process, will it
kill the other thread ?


public void init() throws javax.servlet.ServletException {

Thread myThread = new MyThread();

myThread.start();



myThread is in an infinite loop and it is never
supposed to stop unless we kill the JVM.



Thanks

Re: Basic Thread question

Posted By:   Laurent_Mihalkovic  
Posted On:   Sunday, June 8, 2003 09:42 AM

hmm... It depends on what you call 'kill the JVM'. Sending a termination signal to the JVM process from the Unix command line or using the Task Manager on Windows will stop any JVM in its tracks, no matter what your code says. That is one of the prerogatives of the operating system, to expell any guest at any time... the consequence of this action could be a leakage of system resources that would not be realeased properly by the JVM to the underlying OS.


The other possible meaning of 'kill', is initiate a termination from within the JVM itself. In this case, the JVM will only terminate when the last non-daemon threads has terminated execution. So as suggested, daemon threads can still be present in the system at the time of shutdown and not trigger a continuation.

cheers
laurent

Re: Basic Thread question

Posted By:   Jeff_Drost  
Posted On:   Sunday, May 4, 2003 07:42 PM

Take a look at Thread.setDaemon()


From Thread API...

Marks this thread as either a daemon thread or a user thread. The Java Virtual Machine exits when the only threads running are all daemon threads.

Re: Basic Thread question

Posted By:   Ivo_Limmen  
Posted On:   Wednesday, April 16, 2003 09:27 AM

All activity in the JVM is stopped when exiting the JVM.
About | Sitemap | Contact