aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads' name can be the same? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads Watch "Threads New topic
Author

Threads' name can be the same?

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

Hi everybody,
Directly from here: http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html:
Every thread has a name for identification purposes. More than one thread may have the same name. If a name is not specified when a thread is created, a new name is generated for it.


Do they mean that 2 threads named by the JVM may have the same name after a few numbers? like Thread-0 Thread-1 Thread-2 and then again Thread-0? Or is it referring only to the fact that we can assign manually the same name to different threads?(hope this last one is the reality, otherwise there would not be much sense (at least to me));
Thanks in advance.



OCAJP 7, OCPJP 7
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

It's the latter (i.e. you can call a Thread whatever you like, including giving two or more Threads the same name). In general the JVM will give them unique names but I don't believe the documentation says specifically that will happen, it's just an implementation detail.
 
 
subject: Threads' name can be the same?