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 meant by method overriding?
What is return used for in java?
Define how does a try statement determine which catch clause should be used to handle an exception?
What is the difference between multiple processes and multiple threads?
What are the advantages of compiled language?
What is the synchronized method modifier?
Objects or references which of them gets garbage collected?
How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?
why using interface interface ?
Can you use this() and super() both in a constructor?
Explain different forms of polymorphism?
How do you sort a set in java?
What is a dot notation?
What is the difference between stringbuffer and stringbuilder class?
What is procedure writing?