Java Puzzle – spot the bad code
What’s the most important fault in the following java code (thanks to Roman for both writing and finding the bug :))?
public class Worker extends Runnable { ... @Override public void run() { while(true){ synchronized (emailMessages){ try { while(emailMessages.isEmpty()){ emailMessages.wait(); } mappings.saveMultiple(emailMessages); }catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } finally{ emailMessages.clear(); } } } } } |