Tracking threads in an application
Hi,
My current application consists of a main thread which spawns multiple threads on startup. The main thread is like a daemon thread which is supposed to continuously run and monitor the threads it had spawned.
As long as the main thread is running it has the handle of all the threads it had spawned.
But if for some reason the main thread dies, how do i get a handle back to the threads the main thread had originally spawned.
I don't have the option to even serialize the child thread info as Thread objects cannot be serialized.
Anyone can suggest a better design or a way to handle this scenario?
[645 byte] By [
Suhasaa] at [2007-11-27 8:35:17]

# 1
Threads don't just die. They either return from their run() method, which you can see as you are providing the run() method, or the main() method, or they throw exceptions, which you can catch.
If your main thread is supposed to be monitoring the other threads, let it do that and nothing else.
ejpa at 2007-7-12 20:31:47 >

# 2
I do agree that threads do don't just die. In the eventuality that a exception is thrown and the main comes out of the run method, i need to have a mechanism wherein when i run the main thread ( manager ) i can get retrieve the handle for the threads that were already spawned.
Its basically that a Manager spawns some worker threads and these threads run individually but there is a handle with the Manager. If the Manager thread is killed then I can restart the manager thread and it can resume its monitoring activity by getting the handle back to the child threads..
Am just wondering is the design too complicated if i implement using threads or can i use JMS or some other J2EE technology for the same functionality.
# 3
> I do agree that threads don't just die. In the eventuality that a exception is thrown and the main comes out of the run method, ...
Those two statements are mutually contradictory.
Think about it. Exactly when will this happen? How will the main thread die without going through your finally block in the run() method? or your catch (Throwable t) at the bottom of the main() method? or your UncaughtExceptionHandler?
You're trying to solve a problem that doesn't exist.
ejpa at 2007-7-12 20:31:47 >

# 5
I seem to have been involved in exactly the same debate a couple of months ago. Same result, too, i.e. nil. Mutual incomprehension.
ejpa at 2007-7-12 20:31:47 >
