我正在编写一个远程Android服务,该服务将被许多其他编写应用程序的开发人员绑定。我看到如果太多远程客户端连接或某些滥用客户端忘记断开与我的服务断开连接,那么我的进程可能会耗尽本机资源,虚拟机将向我的进程发送信号并将其终止。我希望通过pid或uid记录来自每个应用程序的连接来保护我的应用程序免受此类情况的影响,如果从特定应用程序建立的连接太多,则强制删除连接以释放资源。关于是否或如何实现这一点的任何想法?
SIGABRT看起来像这样:
pid: 6394, tid: 6539, name: Binder_3 >>> com.my.app <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
#00 pc 00021f98 /system/lib/libc.so (tgkill+12)
#01 pc 00013075 /system/lib/libc.so (pthread_kill+48)
#02 pc 00013289 /system/lib/libc.so (raise+10)
#03 pc 00011f57 /system/lib/libc.so
#04 pc 0002184c /system/lib/libc.so (abort+4)
#05 pc 00045fd7 /system/lib/libdvm.so (dvmAbort+78)
#06 pc 0004d723 /system/lib/libdvm.so
#07 pc 0004fff9 /system/lib/libandroid_runtime.so
#08 pc 00071b07 /system/lib/libandroid_runtime.so (android::javaObjectForIBinder(_JNIEnv*, android::sp<android::IBinder> const&)+174)
#09 pc 0006affb /system/lib/libandroid_runtime.so
#10 pc 0001de8c /system/lib/libdvm.so (dvmPlatformInvoke+112)
#11 pc 0004e46b /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
#12 pc 000272a0 /system/lib/libdvm.so
#13 pc 0002e31c /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
#14 pc 0002b980 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
#15 pc 00060905 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+336)
#16 pc 0004d1d1 /system/lib/libdvm.so
#17 pc 0006cceb /system/lib/libandroid_runtime.so
#18 pc 00070eef /system/lib/libandroid_runtime.so
#19 pc 00019269 /system/lib/libbinder.so (android::BBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+60)
#20 pc 0001d80b /system/lib/libbinder.so (android::IPCThreadState::executeCommand(int)+490)
#21 pc 0001db9b /system/lib/libbinder.so (android::IPCThreadState::getAndExecuteCommand()+38)
#22 pc 0001dc11 /system/lib/libbinder.so (android::IPCThreadState::joinThreadPool(bool)+48)
#23 pc 00021a35 /system/lib/libbinder.so
#24 pc 0000ea61 /system/lib/libutils.so (android::Thread::_threadLoop(void*)+216)
#25 pc 0004d159 /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+68)
#26 pc 0000e593 /system/lib/libutils.so
#27 pc 0000d1b0 /system/lib/libc.so (__thread_entry+72)
#28 pc 0000d348 /system/lib/libc.so (pthread_create+240)
在logcat中我看到:
JNI ERROR (app bug): global reference table overflow (max=51200)
JNI global reference table (0x6dae5008) dump:
Last 10 entries (of 51200):
51199: 0x430a3398 java.lang.ref.WeakReference
51198: 0x430a3348 android.os.RemoteCallbackList$Callback
51197: 0x430a32b8 java.lang.ref.WeakReference
51196: 0x430a3268 android.os.RemoteCallbackList$Callback
51195: 0x430a3038 java.lang.ref.WeakReference
51194: 0x430a31d8 java.lang.ref.WeakReference
51193: 0x430a2f58 java.lang.ref.WeakReference
51192: 0x430a2f08 android.os.RemoteCallbackList$Callback
51191: 0x430a2e78 java.lang.ref.WeakReference
51190: 0x430a2e28 android.os.RemoteCallbackList$Callback
Summary:
223 of java.lang.Class (191 unique instances)
2 of java.lang.String (2 unique instances)
25487 of java.lang.ref.WeakReference (25487 unique instances)
1 of android.app.ActivityThread$ApplicationThread
8 of android.app.LoadedApk$ReceiverDispatcher$InnerReceiver (8 unique instances)
1 of android.app.LoadedApk$ServiceDispatcher$InnerConnection
30 of android.content.ContentProvider$Transport (30 unique instances)
5 of android.database.ContentObserver$Transport (5 unique instances)
1 of android.hardware.display.DisplayManagerGlobal$DisplayManagerCallback
1 of android.opengl.EGLDisplay
1 of android.opengl.EGLSurface
1 of android.opengl.EGLContext
1 of com.my.app.MyClass$1
1 of com.android.dex.Dex
1 of com.my.app.MyBinder
25436 of android.os.RemoteCallbackList$Callback (25436 unique instances)
Failed adding to JNI global ref table (51200 entries)