Minimum number of threads of "Hello World"

H

HVPQ

Hi there,
I got asked this question during recent group discussion: "What is the
minimum number of threads that a simple non-threaded Java program,
like 'Hello World', has?". I answered "Two thread groups: the system
and main thread groups. In the main thread group, there is only 1 main
thread. In the system thread group, there are a garbage collector, a
signal dispatcher, an object reference handler, and a compile thread.
So there are five."
I believe there are more since the person who posed the question said
there are eight of them in total. Do you know? Please help.
Thanks,
HQ
 
C

Chris Smith

HVPQ said:
Hi there,
I got asked this question during recent group discussion: "What is the
minimum number of threads that a simple non-threaded Java program,
like 'Hello World', has?". I answered "Two thread groups: the system
and main thread groups. In the main thread group, there is only 1 main
thread. In the system thread group, there are a garbage collector, a
signal dispatcher, an object reference handler, and a compile thread.
So there are five."
I believe there are more since the person who posed the question said
there are eight of them in total. Do you know? Please help.

There is no defined answer. It depends on the virtual machine vendor
and version, operating system, etc. Way too many variables to expect to
ask that question and get a reasonable answer.

On my implementation (Sun J2RE 1.4.1_02, running on Windows XP), I see
four Java threads: "main", "Finalizer", "Reference Handler" and "Signal
Dispatcher".

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
R

Roedy Green

I believe there are more since the person who posed the question said
there are eight of them in total. Do you know? Please help.

The question only makes sense in terms of a some given JVM. Those are
all implementation details not nailed down by the JVM spec.
 
R

Robert Olofsson

HVPQ ([email protected]) wrote:
: ....
: like 'Hello World', has?". I answered "Two thread groups: the system
: and main thread groups. In the main thread group, there is only 1 main
: thread. In the system thread group, there are a garbage collector, a
: signal dispatcher, an object reference handler, and a compile thread.
: So there are five."
: I believe there are more since the person who posed the question said
: there are eight of them in total. Do you know? Please help.

That depends on the jvm. SUN jdk/1.4.2, linux hello world starts:
0x808aa08 Finalizer system <unknown>
0x8089e50 Reference Handler system <unknown>
0x4cf01008 Signal Dispatcher system <unknown>
0x8052190 main main system

If the garbage collector runs in a separate thread or in the other
threads depends on which GC you have selected.
Also if you start up swing and/or awt you will normally find a

AWT-EventQueue-0, AWT-Motif (linux only, windows may have a similar
thread), AWT-Shutdown and a Java2D Disposer. This is for a program
that calls JOptionPane.showInputDialog, if you start to have lots of
windows and a few modal dialog I think that you may have more
AWT-EventQueues.

If you want to test a jvm I suggest that you write a class that finds
all threads and threadgroups or that you use a profiling tool to find
out (I used my profiler, jmp, to find out the above)...

/robo
 
S

Suresh

If you want to test a jvm I suggest that you write a class that finds
all threads and threadgroups or that you use a profiling tool to find
out (I used my profiler, jmp, to find out the above)...

One could also use the jdb that comes with java. Use the threads command
from jdb to list all the threads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top