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 is difference in between java class and bean?
What classes of exceptions may be thrown by a throw statement?
what is function overloading in java?
What is the unit of plancks constant?
Is void a return type?
What is the difference between multiple processes and multiple threads?
What is map in java?
What is java and its types?
Can a class be declared as protected?
What is the difference between abstract class and interface1? What is an interface?
What is the difference between a static and a non-static inner class in java programming?
can java object be locked down for exclusive use by a given thread? Or what happens when a thread cannot acquire a lock on an object? : Java thread
What is final method in java?
What is the primitive type byte?
Implement two stacks using a single array.