Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Why java is considered as platform independent?

963


Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?

1024


Can I extend singleton class in java?

1038


Difference between a class and an object?

966


What is the console in java?

1093


What about features of local inner class?

1009


What is unicode full form?

929


Does java support multiple inheritance or not?

1022


Can you inherit a constructor java?

1019


What is executor memory?

889


Explain different ways of creating a thread?

985


What is purpose of find feature?

1033


What is difference between overloading and overriding in java?

967


What is Enum in Java?

1206


When should I use stringbuffer?

957