简体   繁体   中英

What is the default number of threads running in the JVM?

Recently I've been learning more about thread and I was wondering why the resource monitor shows always 19 threads running for the Java process.

Now my questions are:

  • Is this the VM using 19 threads?

If so:

  • Are you able to access those threads?
  • Is it possible to use these threads for thread pooling?
  • Is it possible to decrease the amount of threads?

If not:

  • What is causing to show up the 19 threads?

I created a small .jar (see bottom for source) that would run and create a fixed threadpool of 5 worker threads. To that pool I sent tasks and I noticed that after all tasks have been handled, the amount of threads java uses goes back to 19.

Are the threads in the fixed threadpool idle or have they been removed and thus new threads are being created whenever new tasks are submitted?

Sorry for the multiple questions in one post.

It depends on the JVM version, the JVM vendor and some settings like which garbage collector is in place (and how the GC is tuned). Also some add-ons like agents or JMX can change the system running threads. And of course all threads started by the actual Java program. You can use the jstack program to actually list them (most of the system threads have obvious names). They include threads for finalisation, GC, the main thread, the Gui threads (if used), also JIT Compiler Threads and reference weakeners.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM