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
Why java is considered as platform independent?
Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?
Can I extend singleton class in java?
Difference between a class and an object?
What is the console in java?
What about features of local inner class?
What is unicode full form?
Does java support multiple inheritance or not?
Can you inherit a constructor java?
What is executor memory?
Explain different ways of creating a thread?
What is purpose of find feature?
What is difference between overloading and overriding in java?
What is Enum in Java?
When should I use stringbuffer?