【发布时间】:2020-01-22 11:04:41
【问题描述】:
我已经阅读过这个问题,但我认为我的情况不同: IllegalMonitorStateException on wait() call
我在 Android Studio 上使用 java。 我得到的错误如下:
MiniatureAnnotations: Problem annotating via GMS.
java.lang.IllegalMonitorStateException: object not locked by thread before wait()
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:422)
at jaw.a(PG:20)
at hnt.b(PG:115)
at com.google.android.apps.messaging.shared.datamodel.action.GenericWorkerQueueAction.b(PG:81)
at eqs.run(PG:1)
at yya.run(PG:3)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at yws.run(PG:4)
at java.lang.Thread.run(Thread.java:764)
我没有在对象上使用锁,而是同步了方法。如:
public synchronized static boolean send(Repository repository, Context context) {
// code... [I do not use wait or notify]
}
或:
public static synchronized void checkWorkers(Context context) {
WorkManager workManager = WorkManager.getInstance(context);
ListenableFuture<List<WorkInfo>> senderWorker = workManager.getWorkInfosByTag(tagSenderWorker);
if (senderWorker.isCancelled()) {
PeriodicSmsWorker.initializePeriodicSmsWorker(context, REPLACE_POLICY);
updateCheckSenderWorker();
} else if (System.currentTimeMillis() - LAST_CHECK_SENDER_WORKER > MAX_TIME_WORKER_INACTIVE) {
updateCheckSenderWorker();
PeriodicSmsWorker.initializePeriodicSmsWorker(context, REPLACE_POLICY);
}
}
如果我不使用等待或通知,为什么会收到 IllegalMonitorStateException?
Edit1:禁用 Dexguard 基于: How to disable Dexguard?
在 gradle 应用程序中:
buildTypes {
release {
//minifyEnabled false
minifyEnabled rootProject.ext.enableDexGuardPlugin
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dependencies {
...
apply plugin: 'com.android.application'
if(rootProject.ext.enableDexGuardPlugin) {
apply plugin: 'dexguard'
}
}
毕业项目:
ext {
roomVersion = '2.2.0-beta01'
archLifecycleVersion = '2.2.0-alpha03'
coreTestingVersion = "2.1.0-rc01"
enableDexGuardPlugin = false
}
但是我有同样的错误。
【问题讨论】:
标签: java android multithreading exception