/** * Add a job output listener for the current instance of the job * * @param listener the listener */ public synchronized void addJobOutputListenerToCurrent(JobOutputListener listener) { // TODO This method has several possible race conditions, but they are all quite rare ExecutionThread t = current; if (t == null) { if (last != null) { listener.jobOutput(last.output.toString()); } return; } while (t.newOutputListener != null) { Thread.yield(); if (t != current) { if (last != null) { listener.jobOutput(last.output.toString()); } return; } } String output = t.output.toString(); listener.jobOutput(output); t.newOutputCharsSent = output.length(); t.newOutputListener = listener; }