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
Is arraylist dynamic in java?
When should we create our own custom exception classes?
What is meant by the value of a variable?
Why string is called as immutable?
What are 5 boolean operators?
When we serialize an object does the serialization mechanism saves its references too?
What is a final class ?
Can substring create new object?
Are global variables initialized to zero?
What are different data types?
Why is stringbuffer called mutable?
Is math an abstract class in java?
Difference between Preemptive scheduling vs. Time slicing?
Can we overload destructor in java?
When the constructor of a class is invoked?