• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Name of default Thread

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic