what is the difference between sleep() and Wait()?
Answer Posted / amitasite
Thread.sleep() is static method which make current running
thread "not runnable" for specific time. Sleeping thread
doesn't release lock. It will transit to "ready to run"
state after specified time elapsed or other thread interrupts.
wait() can be call on shared object. Wait can be call only
if thread has lock. On calling thread it releases lock on
object and transit to "not runnable" state. It wake ups and
transit to "ready to run" state after other thread that got
lock call notify() or notifyAll() on shared object or call
interrupt().
| Is This Answer Correct ? | 11 Yes | 1 No |
Post New Answer View All Answers
What is anti pattern in cyber security?
What are format specifiers in java?
How do you convert an int to a double in java?
What’s the difference between applets and standalone program?
Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)
Which collection is ordered in java?
How to instantiate member inner class?
Why is multithreading important?
What is multi-catch block in java?
What do you mean by inner class in java?
What are conditionals and its types?
What does system.gc() and runtime.gc() methods do?
Why do we need wrapper classes?
How many types of assembly languages are there?
What are the differences between stringbuffer and stringbuilder?