First off I need to clear something basic, assume I have a synchronized block or a synchronized method and one thread already entered the synchronized part and 5 new threads try to access the synchronized part, will they stop running until the first thread leaves the synchronized part? and if they do, will they wait in a prioritized queue?
Second question is regarding monitors, assume I have a the following code:
synchronized(someObject){
//do some stuff
someObject.wait();
}
Is it correct to assume that if a thread runs this code while another thread is waiting on the monitor and then the first thread calls wait, the second thread will enter the code block (I.E. the wait releases someObject
's monitor) ?
And last question is regarding a Singleton implementation, in order to make it thread safe is it enough to synchronize the instantiation line inside the singleton class to make sure it never gets called more than once ? and if so, is this the best practice ?