In java what is the difference between sleep() and wait() .



In java what is the difference between sleep() and wait() ...

Answer / Baljeet Singh

In Java, `sleep()` and `wait()` are methods used for pausing the execution of a thread. However, they have different purposes:
1. The `Thread.sleep()` method causes the currently executing thread to sleep (temporarily stop) for a specified amount of time.
2. The `Object.wait()` method is called by a thread to wait for a specific condition to become true. It releases the current lock on an object and causes the thread to wait until it's notified or interrupted.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

What's the difference between local, global and universal groups? : java security

1 Answers  


What is explicit casting?

1 Answers  


Explain main thread under thread class execution?

1 Answers  


Why is class forname used in java?

1 Answers  


What is serializable in java?

1 Answers  


What is cookie in java?

1 Answers  


Define network programming?

1 Answers  


What are tags in java?

1 Answers  


When is static variable loaded? Is it at compile time or runtime? When exactly a static block is loaded in java?

1 Answers  


What is an entity in java?

1 Answers  


What is cloning in java?

1 Answers  


Which type of stream is in java?

1 Answers  


Categories