Java `OutOfMemoryError` when creating < 100 threads

后端 未结 4 1876
醉梦人生
醉梦人生 2020-12-16 17:26

I\'ve been reading and testing and banging my head on the wall for over a day because of this error.

I have some Java code in a class called Listener t

4条回答
  •  孤城傲影
    2020-12-16 17:51

    It's not missing memory for your new threads, it's missing actual threads. The system is probably stopping you: there's a limit to the number of thread a user can create. You can query it that way:

    cat /proc/sys/kernel/threads-max
    

    Note that you might be impacted by other processes on the same machine, you they create many thread too. You might find this question useful: Maximum number of threads per process in Linux?

提交回复
热议问题