Can we call the Thread.sleep in Synchyronozed block?

Answers were Sorted based on User's Feedback



Can we call the Thread.sleep in Synchyronozed block?..

Answer / veerendra

While the thread is sleeping in a synchronised block means,
you are locking a resource, there might be 'n' number of
contenders for this resources. If the thread goes to sleep
then other threads or processes contending for the resource
will be blocked infinitely.

Is This Answer Correct ?    8 Yes 1 No

Can we call the Thread.sleep in Synchyronozed block?..

Answer / ravikiran

Yes we can call,And should be enclosed between try catch
blocks beacause Interupted exception may be thrown.

Is This Answer Correct ?    4 Yes 1 No

Can we call the Thread.sleep in Synchyronozed block?..

Answer / pramod

ofcourse you can call thread.sleep in synchronized
block,when we call means when there is a possibility of
loop inside the synchronized block.

Is This Answer Correct ?    3 Yes 2 No

Can we call the Thread.sleep in Synchyronozed block?..

Answer / muthusenthil

yes, you can call wait method inside synchronized block but
synchronized block usually allows one by one to penetrate
in.if you call wait method inside it will create a stagnant
circumstance. synchronized block wont allow other threads
inside till this thread in waiting state get notified

Is This Answer Correct ?    2 Yes 2 No

Can we call the Thread.sleep in Synchyronozed block?..

Answer / 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

More Core Java Interview Questions

How does JAVA ClassLoader work?

1 Answers   IBM,


How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?

0 Answers  


Why java is considered as platform independent?

0 Answers  


What is final keyword in java? Give an example.

0 Answers  


What is "Java Native Interface" and how to use it?

1 Answers   IBM,






What is the argument type of main() method?

2 Answers  


Hi Anyone know the model / questions of the Federal bank sample questions for the post of Specialist Officers - Programmers. Please post if anyone have..

0 Answers  


Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification

0 Answers  


Which sorting is best in java?

0 Answers  


If a variable is declared as private, where may the variable be accessed?

0 Answers  


What are the two types of java programming?

0 Answers  


explain different ways of using thread? : Java thread

0 Answers  


Categories