To be able to call notify() you need to synchronize on the same object.
synchronized (someObject) {
someObject.wait();
}
/* different thread / object */
synchronized (someObject) {
someObject.notify();
}
More Related Contents:
- Difference between wait() and sleep()
- Handling exceptions from Java ExecutorService tasks
- “implements Runnable” vs “extends Thread” in Java
- If I synchronized two methods on the same class, can they run simultaneously?
- Turning an ExecutorService to daemon in Java
- Who is calling the Java Thread interrupt() method if I’m not?
- Difference between “wait()” vs “sleep()” in Java
- Handling Exceptions for ThreadPoolExecutor
- CopyOnWriteArrayList throwing CurrentModificationException
- How to restart thread in java? [duplicate]
- How starvation occurs in producer consumer problem
- Waiting for multiple SwingWorkers
- How to start/stop/restart a thread in Java?
- What is recommended way for spawning threads from a servlet in Tomcat
- How to start two threads at “exactly” the same time
- Happens-before relationships with volatile fields and synchronized blocks in Java – and their impact on non-volatile variables?
- MVC Progress Bar Threading
- Why are wait() and notify() declared in Java’s Object class?
- When to use an assertion and when to use an exception
- Which part of throwing an Exception is expensive?
- Why does Java throw NullPointerException here?
- Animations when using Gridbag Layout.
- Stopping a Thread in Java? [duplicate]
- Do Java sockets support full duplex?
- How can I catch all exceptions thrown through reading / writing a file?
- Is there a good way to forcefully stop a Java thread?
- When may we need to use runOnUiThread in android application?
- In Java, what is the difference between catch a generic exception and a specific exception (eg. IOException?)
- How to set up multi-threading in Spring Batch?
- Why does a Java Lambda which throws a Runtime Exception require brackets?