views:

479

answers:

4

Hi,

I would like to run a Java program that uses the Thread class such that each Thread.run() results in running a proper kernel thread. Is there a way to achieve this by passing some command line parameter to the Java VM ? I am running Eclipse using Java 1.5 SDK (and jre1.5.0_18) on a Windows machine. I tried using -XX:+UseBoundThreads, but the task manager seems to be running both the threads (I am using a dual core machine) on the same core (the other core is idle).

Thanks.

+2  A: 

The Windows JVM always uses native threads. However, it is up to the kernel to decide which core to run each thread on. There's absolutely no guarantee that starting two threads will be shared between 2 cores.

Incidentally, I think the UseBoundThreads option is solaris only, but I'm not too sure about that.

skaffman
+5  A: 

I would like to run a Java program that uses the Thread class such that each Thread.run() results in running a proper kernel thread.

If you call Thread.run(), you're not creating separate threads at all, you're executing everything sequentially in the main thread. What you have to do is call Thread.start(), which will create a new Thread and have it execute Thread.run().

Michael Borgwardt
Heh, good catch :)
skaffman
Sorry about the Thread.run(): I was actually calling Thread.start() in code. I got run() and start() mixed up while writing up this question.
+1  A: 

You can attach with jvisualvm to see which threads are running and how much CPU they use.

Thorbjørn Ravn Andersen
A: 

Thanks Guys.. although I don't know the right answer, currently, Java 1.6 in eclipse is giving me almost twice the performance on my dual-core for the code-base i am looking at...also, jvisualvm works great as a profiler..thanks!