I define a global static object as a synchronization lock.
public static Object ConfirmationSynObj = new Object();
The following function is what I wrote, but it throw a IllegalMonitorStateException.
synchronized (Config.ConfirmationSynObj) {
new Thread(new Runnable() {
@Override
public void run() {
//this is a http request
appSignInfo = getAPKSignature(context, pkinfo.packageName);
Config.ConfirmationSynObj.notify();
}
}).start();
try {
Config.ConfirmationSynObj.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (appSignInfo == null) {
return ret;
}
}
Does anyone know how to lock an object or a function in order to prevent the concurrency?