• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When you run a program how many threads will create ?.

 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Suppose If run a program , I am sure that JVM will create main thread to execute the program. But I would like that to know that internally how many threads JVM will create ?. I know that GC is daemon thread. So when it will create ?. Like GC , JVM will create any more threads ?

Please let me know how many threads( including daemon) JVM will create ? and how to find out the running threads in JVM.



Thanks
Praveen
 
fred rosenberger
lowercase baba
Bartender
Posts: 12185
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wouldn't the number of threads created depend on the specific program being run?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this previous discussion which includes a useful code example.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Kumar wrote:and how to find out the running threads in JVM.

Use a profiler.

I'm not sure, but the following also seems to return a Set<Thread> snapshot of the current threads: And ThreadMXBean also seems to be able to return them, although you'll need a bit more code.
 
Soumyajit Hazra
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Rob. If we print it it gives
[Thread[main,5,main], Thread[Attach Listener,5,system], Thread[Reference Handler,10,system], Thread[Signal Dispatcher,9,system], Thread[Finalizer,8,system]]
 
Praveen Kumar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all for wonderful answers :-) . I got much info..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic