Can we call the Thread.sleep in Synchyronozed block?
Answer Posted / anmol mathpal
yes u can but be sure to use it under try-catch block.
Actually synchronized keyword is basically used for locking
purpose. let us consider an example:-
/*This is a synchronized block*/
Synchronized(this){
try{Thread.sleep(1000);}catch(InterruptedException e){}
//Remaining code
}
Now suppose there is s thread in a program say A
let us consider thread A enters the synchronized block
because of sleep method it'll take one second more than its
normal execution time.that's it. it will affect other
threads that are waiting for that particular resource.
without thread.sleep method
Is This Answer Correct ? | 2 Yes | 2 No |
Post New Answer View All Answers
What happens if main method is not static?
What is exception handling in java?
Why destructor is not used in java?
What are operators and its types?
Explain heap sort?
What is an immutable class? How to create an immutable class?
What is the difference between heap and stack memory?
what type of questions asked for barclays technologies pune please send urgent
How to stop a thread in java? Explain about sleep () method in a thread?
What is thread safe java?
I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?
What is the main use of generics in java?
How are the elements of a gridbaglayout organized?
What is a JAR file?
What is outofmemoryerror in java?