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

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

multithreading - Is there a maximum size parameter in Java FixedThreadPool?

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

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

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...