java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Out of memory at java.lang.Thread

// Bug 描述   linux pthread 创建线程 error , 内存栈溢出 

java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Out of memory
	at java.lang.Thread.nativeCreate(Native Method)
	at java.lang.Thread.start(Thread.java:753)
	at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:970)
	at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1038)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1180)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
	at java.lang.Thread.run(Thread.java:784)

 肯定是线程创建太多啦,有代码不合理的地方 ,

这是公司项目的bug,原来写的代码很不规范  ,

项目中乱用线程的地方类似有 

1.timer用的时间 每次都new  ,原来的没有释放 。(项目中service 中每次都new Timer ,资源浪费 )

2.OKHttpClient 有多个 

3.频繁创建线程的地方没有用线程池 。

4.项目中 有一个单次定位的 每次都new AMapClient 进行单次定位 , 定位完成没有掉 stopLocation() ,而且定位还在service 

中,线程越来越来 ,就引发 stack OOM 


基本解决思路是 : 1. 查看代码 线程创建释放 不合理的地方,进行优化 。

2.集成bugly ,看bug log ,查看其它线程,就看到有很多线程 ,其中重复的线程,就是不合理的地方。






猜你喜欢

转载自blog.csdn.net/lsw8569013/article/details/80283895