Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been running tests were the size of a Java FixedThreadPool is modified as a variable. From researching the FixedThreadPool it seems you should be able to have as many threads in the pool as your memory will allow.

My i7 4-core machine easily handles over 4000 "normal" threads, but changing the threadpool size above 1024 deadlocks my tests. The same 1024 threadpool deadlock happens for an M1 macbook and 2-core macbook air. Is there a set max for a the ThreadPool? For sizes until then everything works fine for all machines.

question from:https://stackoverflow.com/questions/65642980/is-there-a-maximum-size-parameter-in-java-fixedthreadpool

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
166 views
Welcome To Ask or Share your Answers For Others

1 Answer

The limit does not resides in jvm memory but in OS per user thread (process) limit. In linux or Mac OS you can check by ulimit -u. here you can find more info Maximum number of threads per process in Linux?

When you create ThreadPoolExecutor with Executors.newFixedThreadPool( nb ) no Thread is create and only a small amount of memory is require for each thread (perhaps zero if the implementation use a LinkedList or a map to keep the Worker (Thread))

other useful info here Maximum number of threads in a JVM?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...