Javalangoutofmemoryerror Pthreadcreate 1040kb Stack Failed Try Again
我的项目是使用viewPager循环播放图片、vr、视频资源,连续播放4个小时左右会崩溃报错: 从log中可以看到java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try once again 内存溢出的运行时异常,但是可以肯定的是app没有内存过高,很不解,再看后面的pthread_create failed可知是在创建线程时报的内存溢出,创建线程怎么会造成内存溢出呢?第一次遇到 只能先找度娘求救了,找到一篇不可思议的OOM ,从这篇博客的讲解可知是线程数过多造成的内存溢出(具体原因分析可查看上述链接)。问题原因可以基本确定了,可是log中无法定位到具体项目代码。 思路很明确,找到频繁创建线程的地方 首先是分析项目代码,比如使用Glide.with(Application.getApplicationContext()),这里为了规避内存泄漏传入了app的上下文而不是所在的组件的,我的想法是这样可能会造成图片加载的线程的声明周期过长不能及时关闭,所以就把传入的上下文又改成了组件的,但是测试后无效。 其次就是轮训检测app的线程数,既然是线程太多造成的,那就看在什么时候线程会增多,方法: 测试发现CPU_COUNT 为1 ,最大容纳线程数为3,但是 threadMap.entrySet().size()为70.。。。。。一脸蒙蔽。 注释掉后问题解决,从上述代码可知getProxyUrl方法内没做非空验证,每次get都会创建一个(newProxy())新的HttpProxyCacheServer ,而且没有地方调用stop,造成每次播放视频都会增加一个线程(sleep状态)。
文章目录
java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Endeavour again异常分析及解决
问题描述:
08-13 16:nineteen:08.472 E/OMXNodeInstance( 4129): setParameter(1021055c:amlogic.avc.decoder.awesome, OMX.google.android.alphabetize.storeMetaDataInBuffers(0x7f000002): Output:1 en=1 blazon=1) ERROR: BadPortIndex(0x8000101b) 08-13 16:xix:08.472 E/ACodec (28956): [OMX.amlogic.avc.decoder.awesome] storeMetaDataInBuffers failed w/ err -2147483648 08-thirteen xvi:19:08.476 Due east/OmxVideoDecoder( 4129): reset input buffer:1920000 08-thirteen 16:19:08.480 E/OMXNodeInstance( 4129): setConfig(1021055c:amlogic.avc.decoder.awesome, ConfigPriority(0x6f800002)) ERROR: UnsupportedIndex(0x8000101a) 08-13 16:19:08.499 E/OmxVideoDecoder( 4129): set output mistake, new BufferCountActual = ix 08-13 16:19:08.499 Eastward/OMXNodeInstance( 4129): setParameter(1021055c:amlogic.avc.decoder.awesome, ParamPortDefinition(0x2000001)) Fault: UnsupportedSetting(0x80001019) 08-13 sixteen:19:08.500 E/OmxVideoDecoder( 4129): prepare output error, new BufferCountActual = 8 08-13 16:xix:08.500 Due east/OMXNodeInstance( 4129): setParameter(1021055c:amlogic.avc.decoder.crawly, ParamPortDefinition(0x2000001)) ERROR: UnsupportedSetting(0x80001019) 08-13 16:nineteen:08.500 E/OmxVideoDecoder( 4129): fix output error, new BufferCountActual = 7 08-13 16:19:08.500 E/OMXNodeInstance( 4129): setParameter(1021055c:amlogic.avc.decoder.awesome, ParamPortDefinition(0x2000001)) ERROR: UnsupportedSetting(0x80001019) 08-xiii 16:xix:08.596 E/OMXNodeInstance( 4129): setConfig(1021055d:google.aac.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001) 08-xiii sixteen:19:09.222 E/audio_route( 4122): unable to detect path 'hdmi' 08-xiii 16:19:x.348 E/SoftAAC2( 4129): ...EOS Filibuster Fourth dimension 200000 us 08-13 sixteen:xix:10.393 E/OMXNodeInstance( 4129): setConfig(1021055e:google.aac.decoder, ConfigPriority(0x6f800002)) Fault: Undefined(0x80001001) 08-13 xvi:nineteen:11.229 E/CrashReport(28956): Coffee Crash Happen cause by ExoPlayerImplInternal:Handler(360) 08-13 16:19:eleven.576 East/CrashReport(28956): stack frame :17, has cause false 08-13 xvi:nineteen:12.229 E/CrashReport(28956): #++++++++++Record By Bugly++++++++++# 08-xiii 16:19:12.229 E/CrashReport(28956): # You can use Bugly(http:\\bugly.qq.com) to go more Crash Detail! 08-13 16:19:12.231 East/CrashReport(28956): # PKG Proper noun: com.qiaofang.qfangadtv 08-thirteen 16:xix:12.231 Eastward/CrashReport(28956): # APP VER: ane.0.7.iii 08-thirteen 16:19:12.245 E/CrashReport(28956): # LAUNCH Time: 2019-08-13 x:43:28 08-thirteen 16:nineteen:12.245 E/CrashReport(28956): # CRASH Blazon: JAVA_CRASH 08-13 16:xix:12.246 E/CrashReport(28956): # CRASH TIME: 2019-08-13 16:19:12 08-thirteen 16:19:12.246 Due east/CrashReport(28956): # CRASH PROCESS: com.qiaofang.qfangadtv 08-13 16:19:12.247 E/CrashReport(28956): # CRASH THREAD: ExoPlayerImplInternal:Handler 08-13 sixteen:19:12.247 Due east/CrashReport(28956): # Written report ID: cde8a724-52ed-4b0f-845e-ed8ef94e74f7 08-13 16:19:12.248 E/CrashReport(28956): # CRASH DEVICE: TX3 Mini ROOTED 08-13 16:19:12.248 E/CrashReport(28956): # RUNTIME AVAIL RAM:208900096 ROM:4055703552 SD:4055703552 08-13 sixteen:xix:12.249 Due east/CrashReport(28956): # RUNTIME Total RAM:880025600 ROM:4431564800 SD:4431564800 08-13 16:19:12.249 E/CrashReport(28956): # CRASH STACK: 08-13 xvi:19:12.249 E/CrashReport(28956): java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try once again 08-13 16:19:12.249 E/CrashReport(28956): at coffee.lang.Thread.nativeCreate(Native Method) 08-thirteen 16:19:12.249 Due east/CrashReport(28956): at java.lang.Thread.kickoff(Thread.java:730) 08-13 xvi:xix:12.249 Eastward/CrashReport(28956): at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941) 08-13 16:xix:12.249 E/CrashReport(28956): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1348) 08-xiii sixteen:19:12.249 Due east/CrashReport(28956): at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:591) 08-xiii 16:19:12.249 Due east/CrashReport(28956): at com.google.android.exoplayer2.upstream.Loader$LoadTask.execute(Loader.coffee:411) 08-13 sixteen:19:12.249 E/CrashReport(28956): at com.google.android.exoplayer2.upstream.Loader$LoadTask.get-go(Loader.java:285) 08-thirteen 16:19:12.249 E/CrashReport(28956): at com.google.android.exoplayer2.upstream.Loader.startLoading(Loader.java:180) 08-xiii 16:nineteen:12.249 Eastward/CrashReport(28956): at com.google.android.exoplayer2.source.ExtractorMediaPeriod.startLoading(ExtractorMediaPeriod.coffee:657) 08-xiii 16:19:12.249 East/CrashReport(28956): at com.google.android.exoplayer2.source.ExtractorMediaPeriod.prepare(ExtractorMediaPeriod.java:209) 08-13 sixteen:19:12.249 Due east/CrashReport(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.maybeUpdateLoadingPeriod(ExoPlayerImplInternal.coffee:1495) 08-xiii 16:19:12.249 Eastward/CrashReport(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.updatePeriods(ExoPlayerImplInternal.java:1367) 08-13 16:nineteen:12.249 East/CrashReport(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.coffee:495) 08-13 16:19:12.249 E/CrashReport(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.coffee:301) 08-thirteen sixteen:19:12.249 E/CrashReport(28956): at android.os.Handler.dispatchMessage(Handler.coffee:98) 08-13 16:xix:12.249 E/CrashReport(28956): at android.os.Looper.loop(Looper.java:154) 08-13 16:nineteen:12.249 E/CrashReport(28956): at android.os.HandlerThread.run(HandlerThread.coffee:61) 08-thirteen 16:xix:12.249 E/CrashReport(28956): #++++++++++++++++++++++++++++++++++++++++++# 08-xiii 16:19:12.881 E/CrashReport(28956): [Util] Failed to outset a thread to execute chore with message: pthread_create (1040KB stack) failed: Try once again 08-13 16:19:12.882 E/CrashReport(28956): [UploadManager] Failed to outset a thread to execute synchronized upload task, add it to queue. 08-13 16:19:12.882 E/CrashReport(28956): sys default final handle start! 08-13 16:19:12.902 E/AndroidRuntime(28956): FATAL EXCEPTION: ExoPlayerImplInternal:Handler 08-13 16:19:12.902 Due east/AndroidRuntime(28956): Process: com.*****.*****, PID: 28956 08-13 xvi:19:12.902 E/AndroidRuntime(28956): coffee.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Attempt again 08-thirteen 16:19:12.902 Eastward/AndroidRuntime(28956): at java.lang.Thread.nativeCreate(Native Method) 08-13 16:19:12.902 East/AndroidRuntime(28956): at coffee.lang.Thread.kickoff(Thread.java:730) 08-13 16:19:12.902 E/AndroidRuntime(28956): at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:941) 08-13 16:xix:12.902 Due east/AndroidRuntime(28956): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1348) 08-13 16:19:12.902 Eastward/AndroidRuntime(28956): at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.coffee:591) 08-13 16:19:12.902 Eastward/AndroidRuntime(28956): at com.google.android.exoplayer2.upstream.Loader$LoadTask.execute(Loader.coffee:411) 08-13 16:19:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.upstream.Loader$LoadTask.start(Loader.java:285) 08-13 16:xix:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.upstream.Loader.startLoading(Loader.java:180) 08-13 sixteen:19:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.source.ExtractorMediaPeriod.startLoading(ExtractorMediaPeriod.java:657) 08-13 16:19:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.source.ExtractorMediaPeriod.fix(ExtractorMediaPeriod.java:209) 08-13 16:xix:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.maybeUpdateLoadingPeriod(ExoPlayerImplInternal.java:1495) 08-13 16:nineteen:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.updatePeriods(ExoPlayerImplInternal.java:1367) 08-13 sixteen:19:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.coffee:495) 08-13 16:19:12.902 E/AndroidRuntime(28956): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:301) 08-13 16:xix:12.902 Due east/AndroidRuntime(28956): at android.bone.Handler.dispatchMessage(Handler.java:98) 08-13 16:xix:12.902 E/AndroidRuntime(28956): at android.os.Looper.loop(Looper.java:154) 08-13 16:xix:12.902 E/AndroidRuntime(28956): at android.os.HandlerThread.run(HandlerThread.coffee:61) 08-13 16:xix:13.047 Due east/Folder ( 4438): Caught an OutOfMemoryError from the folder stub implementation. 08-xiii 16:nineteen:13.047 E/Folder ( 4438): java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again 08-13 16:19:13.047 E/Binder ( 4438): at java.lang.Thread.nativeCreate(Native Method) 08-13 16:xix:13.047 E/Binder ( 4438): at java.lang.Thread.beginning(Thread.java:730) 08-13 16:19:13.047 E/Binder ( 4438): at com.android.server.am.ActivityManagerService.addErrorToDropBox(ActivityManagerService.java:14036) 08-13 xvi:19:13.047 E/Folder ( 4438): at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:13595) 08-13 16:19:thirteen.047 Eastward/Binder ( 4438): at com.android.server.am.ActivityManagerService.handleApplicationCrash(ActivityManagerService.java:13579) 08-xiii 16:19:thirteen.047 E/Binder ( 4438): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:1646) 08-thirteen 16:nineteen:13.047 E/Binder ( 4438): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2807) 08-13 xvi:19:13.047 E/Binder ( 4438): at android.os.Binder.execTransact(Binder.coffee:565) 08-xiii xvi:19:13.149 E/JavaBinder( 4438): *** Uncaught remote exception! (Exceptions are not all the same supported across processes.) 08-xiii sixteen:19:13.149 E/JavaBinder( 4438): java.lang.RuntimeException: Out of memory 08-xiii 16:nineteen:13.149 Eastward/JavaBinder( 4438): at android.os.Binder.execTransact(Binder.java:584) 08-13 sixteen:19:13.149 E/JavaBinder( 4438): Caused past: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try over again 08-13 xvi:nineteen:13.149 E/JavaBinder( 4438): at java.lang.Thread.nativeCreate(Native Method) 08-13 16:19:thirteen.149 E/JavaBinder( 4438): at java.lang.Thread.start(Thread.java:730) 08-13 16:19:13.149 E/JavaBinder( 4438): at com.android.server.am.ActivityManagerService.addErrorToDropBox(ActivityManagerService.coffee:14036) 08-13 xvi:19:13.149 Eastward/JavaBinder( 4438): at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:13595) 08-xiii 16:xix:13.149 E/JavaBinder( 4438): at com.android.server.am.ActivityManagerService.handleApplicationCrash(ActivityManagerService.coffee:13579) 08-thirteen sixteen:xix:13.149 E/JavaBinder( 4438): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:1646) 08-13 16:19:thirteen.149 E/JavaBinder( 4438): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2807) 08-13 16:19:xiii.149 E/JavaBinder( 4438): at android.bone.Binder.execTransact(Folder.java:565) 08-13 16:nineteen:13.481 Due east/OMXNodeInstance( 4129): !!! Observer died. Speedily, do something, ... annihilation... 08-13 sixteen:xix:xiii.481 E/OMXNodeInstance( 4129): !!! Observer died. Quickly, mName:=amlogic.avc.decoder.crawly 08-thirteen 16:xix:13.482 E/OMXNodeInstance( 4129): !!! Observer died. Quickly, do something, ... anything... 08-13 sixteen:19:13.482 E/ThreadWorker( 4129): pthread on get out wait clean
问题分析:
代码定位思路:
行动:
Map<Thread, StackTraceElement[]> threadMap = Thread.getAllStackTraces(); threadMap.entrySet().size() 另外就是设备支持的线程数 individual val CPU_COUNT = Runtime.getRuntime().availableProcessors() //核心线程数量大小 private val corePoolSize = Math.max(2, Math.min(CPU_COUNT - 1, 4)) //线程池最大容纳线程数 private val maximumPoolSize = CPU_COUNT * 2 + one
3. 既然代码里分析不出,那就借助工具吧,第一个想到的当然就是AS自带的profiler(使用方法详见Android性能优化之CPU Profiler)了,里面有cpu的使用情况和线程总数,下图中标红位置:
图中线程数53是我问题修复后的数值,修复前会随着app播放时长的累加慢慢增加到几百崩的时候估计就上千了,左边有个threads下拉框可以查看所有线程信息,可以看到基本所有线程都是sleep的,所以Thread.getAllStackTraces()这个方法拿到的是存在的线程数而不是正在执行的线程数,但是很明显sleep中的线程也是在占用资源的,因此猜测崩溃是由于存放线程的栈溢出了。那么是哪里创建的线程呢,还是无法明确定位,一个方法就是看上图中app在什么时候会增加了线程数后没有回到原来的数值(对比其他app可知正常情况下上图中线程数增加后会再回到原来的值,简言之就是会上下波动而不是持续增加),后来发现是在视频加载资源的时候有一段无用的代码没注释掉:
fun getProxy(context: Context): HttpProxyCacheServer? { val app = context.applicationContext as App return app.proxy ?: app.newProxy() } HttpProxyCacheServer proxy = getProxy(App.Companion.getApp().getApplicationContext()); String proxyUrl = proxy.getProxyUrl(url);
knottstherembeens.blogspot.com
Source: https://www.i4k.xyz/article/cui130/99866928
0 Response to "Javalangoutofmemoryerror Pthreadcreate 1040kb Stack Failed Try Again"
Post a Comment