• Post Reply Bookmark Topic Watch Topic
  • New Topic

how many threads start  RSS feed

 
kotha vijaybabu
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all...

when we start executing a simple Java prgram,how many threads start
[i tried in JAVA1.4.1,it is giving 2 and JAVA1.4.2,it is giving 1 howz it possible]
can anybody explain.
and what are the thread names that are running???


vijay
 
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
Your code starts running in one thread. If you create a GUI, that starts an event thread, and your event handlers are invoked on this thread, so that makes two.

Aside from that, the JVM may create any number of additional threads for various purposes. I don't know how you got the numbers "1" and "2", but actually the number is typically much more than this. There are separate threads devoted to garbage collection, running finalizers, and many other system-level tasks. But the important thing to remember is that it's an implementation detail -- every JVM can be, and probably is, different, and it ultimately doesn't matter to your program.
 
kotha vijaybabu
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi earnest

i agree with u

i tried this code

class ThreadDemo {
public static void main(String args[]) {

System.out.println(Thread.activeCount());
}
}

u can check it

vijay
preparing for scjp....
 
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
Note that activeCount() only returns the number of threads in the same thread group as the calling thread. Sun's JVMs generally start with two thread groups -- a "main" group where your main() is called, and a System group where the GC thread and about half a dozen others live. So for Sun JVMs, the number is about 8 or so at startup.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try JConsole against your application. Of course I have no idea how many of the threads it shows are actually running just to support JConsole.
 
Henry Wong
author
Sheriff
Posts: 22852
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Try JConsole against your application. Of course I have no idea how many of the threads it shows are actually running just to support JConsole.


I believe JConsole requires a JMX container -- which isn't available at the JVM level until Java 5. The original poster is trying to compare Java 1.4.1 with Java 1.4.2.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!