Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I run a single-threaded Java program why are there are multiple threads at the OS level?

I run a very simple, single-threaded java program. When I check the threads using command under Ubuntu

ps -eLf

it shows there are 14 threads at OS level. I expect there is only one thread when the program has one thread, and x threads if the program has x threads. Is my expectation wrong?

like image 509
mysql guy Avatar asked Jun 17 '11 13:06

mysql guy


3 Answers

The JVM has its own threads, such as the garbage collector. Try doing a kill -3 <pid> on it, and it will show you all the threads.

like image 176
Paul Tomblin Avatar answered Oct 12 '22 22:10

Paul Tomblin


The JVM has multiple threads running. That is the reason why you see so many threads.

like image 24
RMT Avatar answered Oct 12 '22 22:10

RMT


I believe the Java Virtual Machine always opens up multiple OS threads whenever it starts up, which is why you are seeing what you are seeing. Also, I'm not sure that the Java Thread class uses native threads.

like image 42
Zhehao Mao Avatar answered Oct 12 '22 22:10

Zhehao Mao