Release Synchronized Lock

Something like this is possible with synchronized, or I need to use java.util...Lock:

public void outer() {
 synchronized(lock) {
  inner();
 }
}

public void inner() {
 thing1();
 release(lock) {
  result = doLongNetworkRequest();
 }
 thing2(result);
}
+3
source share
2 answers

You cannot release monitors held during a synchronized block, unfortunately. You will need to use a lock or two to do what you want.

+1
source

You can use java.util.concurrent.locks. They have lock()andunlock()

+5
source