Number of issues you can consider...
firstly - I assume you got the thread dump by doing ctrl-break (I think that's what it is) on the console of the running app...
From your first post, I assumed those listening threads are daemon threads because of the behaviour you're expecting - i.e. when the main thread finishes, the program should exit. Behaviour that is only available if the listener threads (i.e. all but that one main thread) are daemon threads. If they're not, then you have to stop each one individually for the application to exit.
4. Main thread does some more work and then exits
At this point I would expect the program to exit, but it doesn't.
For this to occur, those listener threads would have to be daemon threads.
But it looks like, according to your thread dump, that "thread-6" the only non System thread, is _not_ a daemon thread.
Another avenue you can pursue is to run the VM in debug mode, attach a debugger to it and then you can see exactly what the threads are doing once you've executed your shut down routine.
I don't know how you're starting your VM, if it's in an IDE then this is simple, if not then you can play with the runtime command to start the VM. There's docs I've used a number of
times which help here. When you stop the running program you might be able to check if the threads are in fact daemon threads - calling "isDaemon" on the thread objects (you can call arbitrary code on a paused stack frame in java). There are also ways to get all the running threads from a VM.
If all else fails, use System.exit!
What might help is if you could acquire a thread dump from the technical support guy to make sure that there is no anomaly in what's being done on his side.
As far as information on using threads - A basic book on threading i.e. the syntax, creating, wait, stop, synchronisation... helpful to a point, but that's the easy part. We did a course at Uni which included threading and deadlocks etc and I fall back on that. I haven't seen anything covering these kinds of advanced topics - most of the threading books I've seen tell you how to start/stop/synchronise and then tell you not to use them. If there is a deadlock however, debugging should flag it, 1.5 has some fairly advanced dead lock detections, I'm not sure how much the thread dump itself shows in terms of deadlocks.
Michael Wiles
Java Developer
| "Fritz Meissner"
<[EMAIL PROTECTED]>
Sent by: [email protected] 2006/10/06 04:09 PM
|
|
Unfortunately, I don't create the listener thread. I just say,
sessionnotifier.acceptAndOpen(ListenerObj)
And all the threading is done for me. From what I can see I need to call that setDaemon method before starting the thread.
Fritz
On 10/6/06, Chris Hughes <[EMAIL PROTECTED]> wrote:
A quick and nasty fix for this problem would be "listener_thread.setDaemon(true)". This will cause the listener thread to terminate once the main thread is finished.
This won't fix the underlying problem, but it should help in the mean time.
Regards,
Chris
On 10/6/06, Fritz Meissner <[EMAIL PROTECTED] > wrote:
Hi,
Can anyone tell me, what are common reasons why threads hang around and stop a program from exiting once all its work is done? I have the following situation:
1. Main thread calls a method, which starts up a thread to do stuff, and sets up a listener for certain events
2. The listener informs the main thread once its work is complete
3. Main thread sleeps until it hears from the listener that the new thread's work is finished
4. Main thread does some more work and then exits
At this point I would expect the program to exit, but it doesn't.
I should point out that I don't know the internals of what the new thread is doing, that code is hidden from me. This is all in the context of communicating using JSR-82 for Bluetooth; I am using the Avetana implementation. Their technical support guy to whom I've been talking says he is unable to duplicate the problem. I find this disturbing, because the starting point for my code was the sample code he's testing.
And then another question: where do most people learn how to use threads properly? I've been "taught" threading - but all that involved was learning how to create threads; there was nothing about where to use what, how to avoid deadlock etc. Also nothing specific to Java - only C/C++ for an operating systems course.
Fritz
Disclaimer
Sanlam Life Insurance Limited Reg no 1998/021121/06 - Licensed Financial Services Provider
Disclaimer and Directors
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---
