I'm familiar with basic java threading mechanism, however, got confused about one particular case. Below is the sample code.
static byte[] syncBuf;
// synchronized block of code
synchronized(syncBuf) {
// Call non-synchronized method
methodA(syncBuf);
}
My question is if multiple threads execute the above code, will the next thread block until methodA() is done executing since we are holding the lock on syncBuf which is passed by reference.
EDIT:
What happens if I change above code with the below:
static byte[] syncBuf;
// synchronized block of code
synchronized(syncBuf) {
// Call non-synchronized method in a new thread
new Thread(new Runnable() {
@Override
public void run() {
methodA(syncBuf);
}}).start();
}
Would the above interpretation still hold? Will the next thread block until methodA()-thread is done executing?