I have the following problem. Given the EventNotifier interface for the observer pattern:
public interface EventNotifier { void newEvent(final String value); }
A class that implements this interface can register in another class, which often calls the newEvent method. The interface is provided by an external library, so I cannot change it. So far I have implemented it with an anonymous class:
Thread t = new Thread(new Runnable() { @Override public void run() { watcher = new Watcher(new EventNotifier() { @Override public void newEvent(String value) {
For better readability of the code, I would like to open this anonymous class in a new class that extends Thread (because processing should be parallel to other things).
How can I write Thread that does nothing (without an infinite loop, etc.), but wait for the newEvent method to be called? The problem is that newEvent will be called more than 20 times per second, so I cannot start a new thread for every call, but it should all be in the thread.
Hope you have a problem and someone can help me.
source share