Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Name of default Thread  RSS feed

 
Luqman Qaiser
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Suppose there is class A

class A extends Thread{

public void method1(){

Thread abc = new Thread();
abc.start();

}

public void run(){
//do something;
}

}

There are two thread running one is "abc" and other is the default thread in whcih the method1 is running.
How can i determine the name of default thread.

Thanks and regards,
Lucky.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, your example doesn't make much sense to me. Is method1 supposed to be creating an instance of "A" rather than of "Thread"?

In any case, Threads do indeed have a "name" -- you can call getName() on any Thread object to get its name. But the name of the main Thread, or of any other thread created by the JVM itself, is arbitrary -- it could be anything at all. So if that's what you're asking about, the answer is that there's no way to know in advance, but method1() can call Thread.currentThread().getName() to get the main Thread's name at runtime.

If you're asking something else, then you're going to have to explain your question more clearly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!