java - unable to create new native thread
怪我咯
怪我咯 2017-04-18 09:31:15
0
2
1050

我有一个程序主线程需要不断创建子线程,然后分配任务给该子线程执行。执行完之后子线程就没用了。
然后报出了java.lang.OutOfMemoryError: unable to create new native thread异常。
①java 的内存回收机制不会回收执行 完run方法的线程吗???
②java的线程的start方法只能调用一次,那么怎么复用已经存在的且执行完run方法的线程呢?
③如何解决该异常呢?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
小葫芦

Use java thread pool

伊谢尔伦
  1. The Java memory recycling mechanism will recycle threads that have finished executingrun. In this situation you encountered, it is probably that the threads were created too fast, causing most of the created threads to still be running

  2. Use thread pool, same as @xixicat

  3. The total number of threads that the system can create depends on the operating system, so in order to solve this exception, use the thread pool

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template