wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Thread::setName(string) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread::setName(string)" Watch "Thread::setName(string)" New topic
Author

Thread::setName(string)

Aby Krishna
Greenhorn

Joined: Jul 10, 2010
Posts: 14
Hi,
A quick question, what will happen if i invoke setName(String) API on a thread instance after it has been started via "start()". Will the name be at on the thread and printing it would print the new name? or the name can not be set after the thread has been started?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

If the current thread is allowed to access the thread that you are trying to rename, yes.


[My Blog]
All roads lead to JavaRanch
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Don't you try it? Have a look on this API


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
subodh k kumar
Greenhorn

Joined: Aug 19, 2009
Posts: 16

Yes,Inside your run() method you can access the Current thread and reset the name of it.This will print the new Thread Name.
Thread currentThread = Thread.currentThread();
currentThread .setName("newName");

SCJP1.4 , SCWCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread::setName(string)