Android GCM有时应用程序崩溃,因为com.google.Android.gms.GCM.GcmListenerService被java.util.concurrent.ThreadPoolExecutor拒绝
由于我将GCM升级到8.4.0,我的应用程序有时会崩溃,日志显示以下异常:Android GCM有时应用程序崩溃,因为com.google.Android.gms.GCM.GcmListenerService被java.util.concurrent.ThreadPoolExecutor拒绝,android,crash,google-cloud-messaging,runtimeexception,Android,Crash,Google Cloud Messaging,Runtimeexception,由于我将GCM升级到8.4.0,我的应用程序有时会崩溃,日志显示以下异常: Fatal Exception: java.lang.RuntimeException: Unable to start service com.myapp.app.Service_GCMListenerService@ea3f6c7 with Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.myapp.app cmp=
Fatal Exception: java.lang.RuntimeException: Unable to start service com.myapp.app.Service_GCMListenerService@ea3f6c7 with Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000010 pkg=com.myapp.app cmp=com.myapp.app/.Service_GCMListenerService (has extras) }: java.util.concurrent.RejectedExecutionException: Task com.google.android.gms.gcm.GcmListenerService$1@7b28d65 rejected from java.util.concurrent.ThreadPoolExecutor@f392a3a[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 0]
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3027)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by java.util.concurrent.RejectedExecutionException: Task com.google.android.gms.gcm.GcmListenerService$1@7b28d65 rejected from java.util.concurrent.ThreadPoolExecutor@f392a3a[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2014)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:794)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1340)
at com.google.android.gms.gcm.GcmListenerService.zzn(Unknown Source)
at com.google.android.gms.gcm.GcmListenerService.onStartCommand(Unknown Source)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3010)
at android.app.ActivityThread.-wrap17(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1442)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
此崩溃无法解释代码中的错误在哪里。我该怎么办
这是我对GCM的实施:
Android清单:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myapp.app" />
</intent-filter>
</receiver>
<service
android:name=".Service_GCMListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".Service_IDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
服务\u IDListenerService
public class Service_GCMListenerService extends GcmListenerService {
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
PushManager.checkForNewPush();
}
@Override
public void onMessageReceived(String from, Bundle data) {
super.onMessageReceived(from, data);
PushManager.processPush(this,false,data.getString("message"));
}
}
public class Service_IDListenerService extends InstanceIDListenerService {
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. This call is initiated by the
* InstanceID provider.
*/
@Override
public void onTokenRefresh() {
GCMUtils.registerNewInstanceID();
}
AsyncTask的
THREAD\u POOL\u EXECUTOR
的硬编码限制为队列中的128个任务。您的问题是,您正在该执行器上执行许多任务
如果您没有对任何异步任务直接调用
executeOnExecutor
,最可能的罪魁祸首是返回ListenableFuture
的第三方方法,尤其是那些执行网络操作的方法。您可能需要一种串行执行这些命令的方法。将所有这些操作移动到AsyncTask上执行的AsyncTasks中。SERIAL_EXECUTOR将是一个解决方案。感谢您的提示,但我不会直接调用任何AsyncTask,因为Android直接调用sevice com.myapp.app.Service_GCMListenerService。我明白了。我回答的后半部分有帮助吗?我认为您可以在ThreadPoolExecutor中的某个位置设置断点,以查看哪些方法正在生成threadpoolexecuted异步任务。@Meroelyth作为我评论的补充,您希望在其中设置断点的方法是ThreadPoolExecutor.execute
。您不需要重现崩溃来查找问题,只需确定方法调用在代码中的何处生成AsyncTask
,该任务在ThreadPoolExecutor
中运行。我按照您的说明,发现有两个进程调用ThreadPoolExecutor.execute():MeasurementWorker和com.mixpanel.android.viewclawler.viewclawler。这些流程与我的应用程序没有直接关系。我不知道如何阻止他们。我使用MixPanel,但只是在我的应用程序上发送很少的数据。你能分享你的代码吗?我有完全相同的问题。我们也使用Mixpanel。你找到解决办法了吗?