@Override public void run() { try { synchronized (Task.class) { while (lastThread != null) { try { Task.class.wait(); } catch (InterruptedException ex) { // OK wait again } } lastThread = Thread.currentThread(); } notifyRunning(); run.run(); } finally { Item scheduled = this.item; if (scheduled != null && !scheduled.isNew() && scheduled.getTask() == this) { // do not mark as finished, we are scheduled for future } else { notifyFinished(); } synchronized (Task.class) { lastThread = null; Task.class.notifyAll(); } } }
void schedule(long delay) { if (stopped) { return; } time = System.currentTimeMillis() + delay; final Item localItem; synchronized (processorLock) { if (cancelled != null) { cancelled.set(false); } notifyRunning(); if (item != null) { item.clear(null); } item = enableStackTraces ? new SlowItem(this, RequestProcessor.this) : new FastItem(this, RequestProcessor.this); localItem = item; } if (delay == 0) { // Place it to pending queue immediatelly enqueue(localItem); } else { // Post the starter TickTac.schedule(localItem, delay); } }
public void run() { try { notifyRunning(); lastThread = Thread.currentThread(); run.run(); } finally { Item scheduled = this.item; if (scheduled != null && scheduled.getTask() == this) { // do not mark as finished, we are scheduled for future } else { notifyFinished(); } lastThread = null; } }
final Item localItem; synchronized (processorLock) { notifyRunning(); if (item != null) item.clear(); item = new Item(this, RequestProcessor.this);
@Override public void run() { try { synchronized (Task.class) { while (lastThread != null) { try { Task.class.wait(); } catch (InterruptedException ex) { // OK wait again } } lastThread = Thread.currentThread(); } notifyRunning(); run.run(); } finally { Item scheduled = this.item; if (scheduled != null && !scheduled.isNew() && scheduled.getTask() == this) { // do not mark as finished, we are scheduled for future } else { notifyFinished(); } synchronized (Task.class) { lastThread = null; Task.class.notifyAll(); } } }
final Item localItem; synchronized (processorLock) { notifyRunning(); if (item != null) item.clear(); item = new Item(this, RequestProcessor.this);
/** (Re-)schedules a task to run in the future. * If the task has not been run yet, it is postponed to * the new time. If it has already run and finished, it is scheduled * to be started again. If it is currently running, it is nevertheless * left to finish, and also scheduled to run again. * @param delay time in milliseconds to wait (starting from now) */ public void schedule(int delay) { if (stopped) { throw new IllegalStateException("RequestProcessor already stopped!"); // NOI18N } time = System.currentTimeMillis() + delay; final Item localItem; synchronized (processorLock) { notifyRunning(); if (item != null) { item.clear(null); } item = new Item(this, RequestProcessor.this); localItem = item; } if (delay == 0) { // Place it to pending queue immediatelly enqueue(localItem); } else { // Post the starter starterThread.schedule(new EnqueueTask(localItem), delay); } }
void schedule(long delay) { if (stopped) { return; } time = System.currentTimeMillis() + delay; final Item localItem; synchronized (processorLock) { if (cancelled != null) { cancelled.set(false); } notifyRunning(); if (item != null) { item.clear(null); } item = enableStackTraces ? new SlowItem(this, RequestProcessor.this) : new FastItem(this, RequestProcessor.this); localItem = item; } if (delay == 0) { // Place it to pending queue immediatelly enqueue(localItem); } else { // Post the starter TickTac.schedule(localItem, delay); } }