If I have 3000 threads in TIMED_WAIT in Java, what affects the processor?

I have a WorkManager + ThreadPool under Glassfish that uses TIMED_WAIT, for example:

p: thread-pool-1; w: 2018 (TIMED_WAITING):

 at java.lang.Object.wait(Native Method) at com.sun.corba.ee.impl.orbutil.threadpool.WorkQueueImpl.requestWork(WorkQueueImpl.java:171) at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:528)` 

Assume for a moment that the threads do nothing (i.e. no work is ever added). Is there a difference in CPU usage between 100 threads in a pool and 3000 threads in a pool?

Our testing shows that it is not, but I would like to make sure.

+4
source share
1 answer

I would say that it depends on the OS; we have thousands of threads running in our Java server software on a Linux server with NPTL (Native Posix Threading Library), but most of them are “sleeping” most of the time, and CPU usage has never been really high, usually from 5 up to 20% (on one 4-core processor). I could not find any links right now, but I'm sure I read that with NPTL the overhead of sleeping threads is negligible.

+4
source

Source: https://habr.com/ru/post/1399530/


All Articles