Orphan Thread - how to close
I have a program running 2 threads; occasionally the main thread stalls and the worker thread is leaft as an orphan.
How do I close / terminate this orphan thread?
I tried putting a simple time check in the worker thread forcing it to return after a certain elapsed time ( of zero activity from the main thread). But i still suspect the orphan thread is running.
1) Is there a way to check if a thread is still active?
2) Is it necessary to do more than simply return from a thread function to terminate the worker thread? ( after all an orphan has nowhere to return to)
I am Running Ubuntu Linux 12.04, and using NetBeans as the IDE + latest Java.
Thanks
Jefe
Re: Orphan Thread - how to close
Im sorry but I am not familiar enough with the java language to answer your questions, however I do now that there is a Thread.interrupted() method that returns true if the currently executing thread has been asked to interrupt its execution, that may be helpful, but once again I do not know for sure!
Re: Orphan Thread - how to close
What happens if you set the worker Thread as a daemon thread via the Thread method, setDaemon(true)?
1 Attachment(s)
Re: Orphan Thread - how to close
Using daemon threads only works if all non-daemon threads actually terminate, not if they stall.
I'm unfamiliar with the Netbeans IDE, but I would be surprised if it didn't have a stack trace monitor tool you can use to identify which threads are running.
Here's an example stack trace monitor (this is from Eclipse):
Attachment 1516
Re: Orphan Thread - how to close
Quote:
occasionally the main thread stalls
This sounds like a pointer to the real problem.
What do you mean by stall? What options may be available in catching the main thread before or during the stall?
How many threads are you dealing with? Is it just one main thread and a worker or two or something more complex?
Provide as many details as possible...