About 265,000 results
Open links in new tab
  1. wait() Method in Java With Examples - GeeksforGeeks

    Jun 6, 2021 · In java, synchronized methods and blocks allow only one thread to acquire the lock on a resource at a time. So, when wait() method is called by a thread, then it gives up the lock on that resource and goes to sleep until some other thread enters the same monitor and invokes the notify() or notifyAll() method.

  2. wait - How do I make a delay in Java? - Stack Overflow

    public static void wait(int ms) { try { Thread.sleep(ms); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } } and, then you can call this method anywhere like: wait(1000);

  3. wait and notify() Methods in Java | Baeldung

    Jan 8, 2024 · Simply put, calling wait() forces the current thread to wait until some other thread invokes notify() or notifyAll() on the same object. For this, the current thread must own the object’s monitor .

  4. java - Wait x seconds or until a condition becomes true - Stack Overflow

    Dec 7, 2022 · How to wait x seconds or until a condition becomes true? The condition should be tested periodically while waiting. Currently I'm using this code, but there should be a short function. for (int i = 10; i > 0 && !condition(); i--) { Thread.sleep(1000); }

  5. How do I make Java wait for a method to finish before continuing?

    Jan 14, 2014 · So my problem is that I need these methods to run one after another but I cannot work out how to make the methods wait before being run. Any help is appreciated. Thank you. Here is my code: moveEnemy("right",3); wait(); moveEnemy("down",3); wait(); moveEnemy("right",2); wait(); moveEnemy("up",1); wait(); moveEnemy("right",2); wait();

  6. Difference Between wait() and notify() in Java - GeeksforGeeks

    Apr 4, 2022 · wait () method is a part of java.lang.Object class. When wait () method is called, the calling thread stops its execution until notify () or notifyAll () method is invoked by some other Thread. The wait () method has 3 variations: 1. wait (): This is a basic version of the wait () method which does not take any argument.

  7. Demystifying Java wait(), notify(), and join() methods for

    Dec 16, 2023 · The wait(), notify(), and join() methods in Java are used to make one thread wait until another thread has accomplished a certain task.

  8. Java Object wait () Method

    The wait() method can be used to make consumers wait for items and producers wait for space to be available, with a timeout to prevent indefinite waiting. Example

  9. Wait() Method in Java & How Wait() Method Works - JavaGoal

    Mar 25, 2020 · By use of the wait () method a thread is paused (release lock) running in its critical section and another thread can enter (acquire the lock) in the same critical section. So that multiple threads can communicate between the thread by use of use wait () and notify ().

  10. How to Use the wait() and notify() Methods in Java - Delft Stack

    Feb 2, 2024 · The wait() methods can be used in the following different ways: Using wait(): This is the simple calling of the wait() method, which will cause the current thread to wait indefinitely until the other threads invoke the notify() or notifyAll() methods. Using wait(long timeout):

Refresh