问题
I get this warning message and since I see this message I also started to see the Google Play Services isnt responding popup and it closes my application after some time. I have review similar questions but could not find out the reason.
Following is a sample of my handler thread usage. I do not know what to do to avoid this problem.
@Override
public void find(Func1<RealmQuery<Artist>, RealmQuery<Artist>> query,
Action1<Result<List<Artist>>> onResult) {
if (query != null) {
handlerThread = new HandlerThread("MyHandlerThreadArtist");
handlerThread.start();
looper = handlerThread.getLooper();
Handler handler = new Handler(looper);
handler.post(new Runnable(){
@Override
public void run() {
Timber.log(Log.DEBUG, "ARTISTDAOIMPL", "find Thread.currentThread().getName() " + Thread.currentThread().getName());
mDatabase.findRealmObject(Artist.class, query,
result -> onResult.call(
Result.getData(Arrays.asList(result.data.toArray(new Artist[]{})))
), err -> onResult.call(Result.getError(err))
);
}
});
}
12-17 15:56:44.631 2944 2977 W art : Long monitor contention with owner Answers Events Handler1 (2983) at java.lang.Object java.lang.Throwable.nativeFillInStackTrace!()(Throwable.java:-2) waiters=0 in io.fabric.sdk.android.services.common.AdvertisingInfo io.fabric.sdk.android.services.common.IdManager.getAdvertisingInfo() for 274ms
I use fabric to get the crash reports. Not sure if it is related with that or not.
This part is from the traces.txt
file that shows info about Answers Events Handler1 I thought that would be helpful.
"Answers Events Handler1" prio=5 tid=21 Waiting
| group="main" sCount=1 dsCount=0 obj=0x12ca50d0 self=0x9fe5b200
| sysTid=32081 nice=10 cgrp=default sched=0/0 handle=0x9307f920
| state=S schedstat=( 53200042 321330653 137 ) utm=2 stm=3 core=2 HZ=100
| stack=0x92f7d000-0x92f7f000 stackSize=1038KB
| held mutexes=
at java.lang.Object.wait!(Native method)
- waiting on <0x0b62dbce> (a java.lang.Object)
at java.lang.Thread.parkFor$(Thread.java:2127)
- locked <0x0b62dbce> (a java.lang.Object)
at sun.misc.Unsafe.park(Unsafe.java:325)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1091)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1084)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at io.fabric.sdk.android.services.common.ExecutorUtils$1$1.onRun(ExecutorUtils.java:75)
at io.fabric.sdk.android.services.common.BackgroundPriorityRunnable.run(BackgroundPriorityRunnable.java:30)
at java.lang.Thread.run(Thread.java:761)
This is the other one of the similar warning:
12-17 15:16:05.729 32041 32084 W art : Long monitor contention with owner Queue (32074) at boolean android.os.BinderProxy.transactNative(int, android.os.Parcel, android.os.Parcel, int)(Binder.java:-2) waiters=1 in io.fabric.sdk.android.services.common.AdvertisingInfo io.fabric.sdk.android.services.common.IdManager.getAdvertisingInfo() for 267ms
This part is also from the traces.txt
file about "Queue":
"Queue" prio=10 tid=20 Waiting
| group="main" sCount=1 dsCount=0 obj=0x12c56280 self=0x9fe5ad00
| sysTid=32077 nice=10 cgrp=default sched=0/0 handle=0x93249920
| state=S schedstat=( 2336754 827421 7 ) utm=0 stm=0 core=0 HZ=100
| stack=0x93147000-0x93149000 stackSize=1038KB
| held mutexes=
at java.lang.Object.wait!(Native method)
- waiting on <0x061c78c9> (a java.lang.Object)
at java.lang.Thread.parkFor$(Thread.java:2127)
- locked <0x061c78c9> (a java.lang.Object)
at sun.misc.Unsafe.park(Unsafe.java:325)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:519)
at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.performOperation(DependencyPriorityBlockingQueue.java:197)
at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.get(DependencyPriorityBlockingQueue.java:236)
at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:65)
at io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue.take(DependencyPriorityBlockingQueue.java:46)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
First, it was showing specific handler thread names that I used in the application. Currently it does not show them but it prints these ones.
I need to learn that if it is a big issue and how to fix them.
Thanks.
来源:https://stackoverflow.com/questions/59378433/long-monitor-contention-with-owner-warning