Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread.activeCount()  RSS feed

 
Deepak M
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • 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());
}
}
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to Threads...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!