File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Understanding the Thread reference that is returned by call to Thread.currentThread(); Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Understanding the Thread reference that is returned by call to Thread.currentThread();" Watch "Understanding the Thread reference that is returned by call to Thread.currentThread();" New topic
Author

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

Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
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



Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
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


Bye,
Nicola
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
Thanks Nicola.That was helpful to my understanding.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Understanding the Thread reference that is returned by call to Thread.currentThread();