问题描述:

Is something like this possible with synchronized, or do I need to use java.util...Lock:

public void outer() {

synchronized(lock) {

inner();

}

}

public void inner() {

thing1();

release(lock) {

result = doLongNetworkRequest();

}

thing2(result);

}

网友答案:

You can't release the monitors held during a synchronized block unfortunately. You will have to use a lock or two to do what you want.

网友答案:

You can use the java.util.concurrent.locks. They have lock() and unlock()

相关阅读:
Top