由于com.google.android.gms.gcm.GcmListenerService被java.util.concurrent.ThreadPoolExecutor拒绝,因此Android

编程入门 行业动态 更新时间:2024-10-28 10:31:35
本文介绍了由于com.google.android.gms.gcm.GcmListenerService被java.util.concurrent.ThreadPoolExecutor拒绝,因此Android GCM有时应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

自从我将GCM升级到8.4.0以来,我的应用有时会崩溃,并且日志显示以下异常:

since I upgraded GCM to 8.4.0 my app sometimes crashes and the log shows the following exception:

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)

此崩溃不解释我的代码中的错误在哪里.我该怎么办?

This crash does not explain where is the error in my code. What should I do?

这是我对GCM的实现:

This is my implementation of 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>

Service_GCMListenerService

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")); } }

Service_IDListenerService

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_POOL_EXECUTOR的硬编码限制为排队的128个任务.您的问题是您正在该执行程序上执行许多任务.

AsyncTask's THREAD_POOL_EXECUTOR has a hard-coded limit of 128 tasks queued. Your problem is that you are executing a lot of tasks on that executor.

如果您没有在任何AsyncTask上直接调用executeOnExecutor,则最可能的罪魁祸首是返回ListenableFuture的第三方方法,尤其是执行网络操作的第三方方法.您可能需要一种串行执行这些方法的方法.将所有这些操作移到在AsyncTask.SERIAL_EXECUTOR上执行的AsyncTasks中将是一种解决方案.

If you are not directly calling executeOnExecutor on any of your AsyncTasks, the most likely culprit are third-party methods that return a ListenableFuture, especially those performing network operations. You'll probably want a way to execute those serially. Moving all of those operations into AsyncTasks executing on AsyncTask.SERIAL_EXECUTOR would be one solution.

更多推荐

由于com.google.android.gms.gcm.GcmListenerService被java.util.concurrent.ThreadPoolE

本文发布于:2023-09-08 08:19:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466858.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   gcm   GcmListenerService   gms   google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!