Forums Register Login

Understanding the Thread reference that is returned by call to Thread.currentThread();

+Pie Number of slices to send: Send
Hi,
I ran the following code
I know that call to currentThread() returns a reference to the currently executing thread ,but from the output I do not understand the other components that are returned.
Apart of the thread name (Thread-0 or main) what is the meaning of this "5,main"



The following is the output:

Current Thread Thread[main,5,main]
User Thread Thread[Thread-0,5,main] 1
User Thread Thread[Thread-0,5,main] 2
User Thread Thread[Thread-0,5,main] 3
User Thread Thread[Thread-0,5,main] 4
User Thread Thread[Thread-0,5,main] 5
User Thread Thread[Thread-0,5,main] 6
User Thread Thread[Thread-0,5,main] 7
User Thread Thread[Thread-0,5,main] 8
User Thread Thread[Thread-0,5,main] 9



+Pie Number of slices to send: Send
5 is the default Thread priority

the last information, main, is the Thread Group which your current thread belongs to.

You can refer to java6 API to see how interact with those Thread attributes.
You can for example change thread name and priority with setName and setPriority methods

http://java.sun.com/javase/6/docs/api/java/lang/Thread.html


About Thread groups you can read the ThreadGroup class detailed description

http://java.sun.com/javase/6/docs/api/java/lang/ThreadGroup.html
+Pie Number of slices to send: Send
Thanks Nicola.That was helpful to my understanding.
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 10664 times.
Similar Threads
Threads and run()
KATHY SCJP 1.6 : THREADS, exercise 9-2. Is my code fine?
Thread synchronization
Wait method (multithreading) currentmethod
Thread-0?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:24:36.