问题
I'm using this Java version:
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.3) (suse-9.1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
When I start a java program, e.g.
java TestApp
by default, will the JVM run in parallel ?
If so, which parts run in parallel ?
I am interested in this, because I found if I use taskset -c 0 java TestApp
to bind TestApp
running on processor 0
, the first running time is much slower than java TestApp
. Does this imply something?
回答1:
There are a number of single threaded tasks which have a thread of their own.
- the main thread which runs you program
- the background byte code to native compiler
- the finalizer thread (to call finalize() on objects)
- the GC thread pool
Your code will only use as many threads as you create (plus "main" which created for you)
回答2:
The JVM has native threads and no Global Lock, if that's what you're asking.
回答3:
The first running time is probably largely JITing the bytecode to machine code. I would suspect very strongly that process is optimized for parallel scenarios.
来源:https://stackoverflow.com/questions/12219424/does-the-current-hotspot-jvm-run-in-parallel-by-default