Java Threads
THREAD STUFF
CODE:
Here is a little program that plays with some threads, it shows one way to create and use
threads as well as demonstrates some of the ideas discussed below.
SOME EXCENTRICITES:
The jdk call to enumerate only returns threads for which isAlive() is true. The call activeCount()
returns the "true" count of threads. [using j2sdk1.4.2_01]
The difference comes from the fact that activeCount counts threads for which isAlive() is false.
For instance a thread that has been created but not yet (maybe never) started (in this state isAlive=false).
The garbage collector cannot collect the thread object as long as there are references to it.
This is true even if the thread has stopped (thread.stop()). All references to the thread
should manually be removed (dereference the thread) so garbage collection can "take it".
GETTING A THREAD DUMP:
Make sure you are not starting the app with the nohup directive as the nohup directive runs
the command with hangup signals ignored.
You can get a thread dump by using the killall -3 java command [yea a little overkill here]
thread dump should put out the following information for each thread:
thread name
daemon status
java priority
tid [address of thread obj]
nid [native ID]
java state [runnable, waiting, etc..]
[approximate stack limits]