File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Thread::setName(string)" Watch "Thread::setName(string)" New topic


Aby Krishna

Joined: Jul 10, 2010
Posts: 14
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é

Joined: Nov 24, 2005
Posts: 14688

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

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");

I agree. Here's the link:
subject: Thread::setName(string)
jQuery in Action, 3rd edition