I'm running a single threaded Java app on the following java version:
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
with the -XX:+UseSerialGC
option enabled. Still when I start the application I see multiple threads starting when monitoring the system with htop
. I'd like to reduce the number of processes started as much as possible since I have a use case which involves running multiple instances of this application and this will hit the roof of the maximum allowed number of process on the system that I'm running on. Are there any other jvm options other than -XX:+UseSerialGC
that I could use to reduce the number of threads starting?
Each JVM server can have a maximum of 256 threads to run Java applications. In a CICS region you can have a maximum of 2000 threads. If you have many JVM servers running in the CICS region (for example, more than seven), you cannot set the maximum value for every JVM server.
You can change these values by (temporal) running ulimit command or (permanent) editing /etc/security/limits. conf . This value is the system-global (including non-JVM processes) maximum number of threads. Check cat /proc/sys/kernel/threads-max , and increase if necessary.
What Is a Thread in Java? A Java thread is the execution path in a program. Everything that runs in Java is run in threads. Every application in the JVM world has threads, at least one, even if you don't call it explicitly. It all starts with the main method of your code, which is run in the main application thread.
The OS sees JVM as a single process and a single thread. Therefore, any thread created by JVM is supposed to be maintained by it only. Green threads hold all the information related to the thread within the thread object itself.
Apart from -XX:+UseSerialGC
which disables Parallel or Concurrent GC, there are the following options to reduce the number of JVM threads:
-XX:CICompilerCount=1
leaves only one JIT compiler thread.-XX:+ReduceSignalUsage
disables Signal Dispatcher thread. E.g. JVM will not handle SIGQUIT to dump threads.-XX:+DisableAttachMechanism
prevents AttachListener thread from starting.In theory it is possible to disable even more threads (e.g. Service Thread and VM Periodic Task Thread) but this would require patching JVM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With