• 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 count

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why does Thread.activeCount() returns 2 in main even though the only thread is the main thread?
if i enumerate it says null
public class ThreadEnumerate
{

public static void main(String[] args) throws Exception
{
System.out.println(Thread.activeCount());
Thread[] t1=new Thread[Thread.activeCount()];
Thread.enumerate(t1);
for(int i=0;i<t1.length;i++)
{
System.out.println(t1[i]);
}
}
}
output:
2
Thread[main,5,main]
null
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have the answer to your question, but I do have some relevant information.
There is a thread named Thread-0 with unknown state in the same thread group as the main thread.
(1) The list command of the ThreadGroup class displays all the threads in the group. There are two threads, main and Thread-0.

(2)The Java Debugger program jdb displays all the threads. Look at the last two entries in the table.
> jdb Test
> stop in Test.main
> run
main[1] threads

java.util.logging.LogManager
public class LogManager {
private class Cleaner extends Thread {
[ July 09, 2003: Message edited by: Marlene Miller ]
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a guess. Probably the other thread is a garbage collection thread.
 
reply
    Bookmark Topic Watch Topic
  • New Topic