java.lang.InternalError: Thread starting during runtime shutdown

前段时间写一个小项目练手,在使用UncaughtExceptionHandler上传错误报告的时候一直出现java.lang.InternalError: Thread starting during runtime shutdown这样一个异常,百思不得其解,后来在StackOverFlow上找到了解决办法,决定记录下来。
java.lang.InternalError: Thread starting during runtime shutdown at java.lang.Thread.nativeCreate(Native Method)
at java.lang.Thread.start(Thread.java:1042) at org.apache.http.impl.conn.tsccm.AbstractConnPool.enableConnectionGC(AbstractConnPool.java:140)
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.createConnectionPool(ThreadSafeClientConnManager.java:120) 
at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.<init>(ThreadSafeClientConnManager.java:98) 
StackOverFlow中大神的解释是:当前线程开启的太晚,也就是说当我在UncaughtExceptionHandler接收到未捕获的异常时,开启一个子线程来上传错误日志,在上传错误日志时创建了HttpClient,但是HttpClient在创建时设置了ThreadSafeClientConnManager来管理连接,通过查看ThreadSafeClientConnManager的源码发现,ThreadSafeClientConnManager也开启了子线程,这就出现了在子线程中开启子线程的问题,这就会导致uncaughtException()在执行完成后线程中的线程才开启,就会抛出java.lang.InternalError: Thread starting during runtime shutdown。
这个问题的解决方案是:提前创建HttpClient,因为HttpClient创建是也会开启线程,避免在uncaughtException()中创建,从而避免了在线程中开启线程的问题。
public boolean adoptSessionInfo(SessionInfo session) { if (session.basicInfoSync()) { if (isTerminating) { return false; // 应用正在关闭,拒绝新会话 } SessionInfo old = null; String clientId = session.getClientId();//basicInfoSync之后就有clientId了 ALog.i("-----------client Id is:"+clientId); synchronized(sessions) { for (SessionInfo tmp : sessions) { if (clientId.equals(tmp.getClientId())) { old = tmp; break; } } if (old != null) { sessions.remove(old); } sessions.add(session); } if (old != null) { old.cleanUp(); } startProtocolThread(session); return true; } return false; } 报错08-07 14:59:08.943 3031 4106 I stbserver-com.taixin.stbserver.SessionInfo: [basicInfoSync:338]send basic info sync:connection {"volume":0,"areacode":"","boxno":"94810100916","dtv_type":"-1","program_version":"1.0","area_name":"","boxshortno":"886702996","boxmodel":"T70","protocolVersion":"v002.000.001","is_support_tv_prepared_status":"true","is_support_muti_code_rate":"true","account":"143606","name":"box94810100916","phonemac":"bab8c8e0d7d4","natype":-1,"boxVersionCode":6094} 08-07 14:59:08.943 3031 4106 I stbserver-com.taixin.stbserver.ProtocolHub: [adoptSessionInfo:134]-----------client Id is:andbab8c8e0d7d4 08-07 14:59:08.944 3031 4106 W System.err: java.lang.InternalError: Thread starting during runtime shutdown 08-07 14:59:08.944 3031 4106 W System.err: at java.lang.Thread.nativeCreate(Native Method) 08-07 14:59:08.944 3031 4106 W System.err: at java.lang.Thread.start(Thread.java:730) 08-07 14:59:08.945 3031 4106 W System.err: at com.taixin.stbserver.ProtocolHub.startProtocolThread(ProtocolHub.java:213) 08-07 14:59:08.945 3031 4106 W System.err: at com.taixin.stbserver.ProtocolHub.adoptSessionInfo(ProtocolHub.java:150) 08-07 14:59:08.945 3031 4106 W System.err: at com.taixin.stbserver.LanConnection$1.run(LanConnection.java:71) 08-07 14:59:08.945 3031 4106 W System.err: at java.lang.Thread.run(Thread.java:761) 08-07 14:59:08.945 3031 4106 I stbserver-LiveStreamManager: term
最新发布
08-08
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值