• 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

Thread.activeCount()

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does 'active' thread mean in Java ???
In the program below, main thread dies before the child thread, but it still remains active. Can anyone explain this ?
class MyThread implements Runnable {
static Thread main;
public void run() {
try {
for(int i = 0; i < 1000; i ++ ) {
Thread.sleep(5);
}
} catch(Exception e) {}
System.out.println("Main Thead is running :" + main.isAlive());
System.out.println("Active Threads in Thread Group :" + Thread.currentThread().getThreadGroup().getName() + " " + Thread.activeCount());

}

public static void main(String[] args) {
main = Thread.currentThread();
Thread t = new Thread(new MyThread());
t.start();
System.out.println("Active Threads in Thread Group :" + t.getThreadGroup().getName() + " " + Thread.activeCount());
}
}
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to Threads...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic