public Future<?> schedule(Runnable work, long delay, TimeUnit unit) { if(work == null) return null; Future<?> retval=null; long key=System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, unit); // execution time Entry task=new Entry(work); while(!isShutdown()) { Entry existing=tasks.putIfAbsent(key, task); if(existing == null) { retval=task.getFuture(); break; // break out of the while loop } if((retval=existing.add(work)) != null) break; // Else the existing entry is completed. It'll be removed shortly, so we just loop around again. // Don't remove the entry ourselves - see JGRP-1457. } if(key < next_execution_time || no_tasks.compareAndSet(true, false)) { if(key >= next_execution_time) key=0L; taskReady(key); } return retval; }
public Future<?> schedule(Runnable work, long delay, TimeUnit unit) { if(work == null) return null; Future<?> retval=null; long key=System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, unit); // execution time Entry task=new Entry(work); while(!isShutdown()) { Entry existing=tasks.putIfAbsent(key, task); if(existing == null) { retval=task.getFuture(); break; // break out of the while loop } if((retval=existing.add(work)) != null) break; // Else the existing entry is completed. It'll be removed shortly, so we just loop around again. // Don't remove the entry ourselves - see JGRP-1457. } if(key < next_execution_time || no_tasks.compareAndSet(true, false)) { if(key >= next_execution_time) key=0L; taskReady(key); } return retval; }
public Future<?> schedule(Runnable work, long delay, TimeUnit unit) { if(work == null) return null; Future<?> retval=null; long key=System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, unit); // execution time Entry task=new Entry(work); while(!isShutdown()) { Entry existing=tasks.putIfAbsent(key, task); if(existing == null) { retval=task.getFuture(); break; // break out of the while loop } if((retval=existing.add(work)) != null) break; // Else the existing entry is completed. It'll be removed shortly, so we just loop around again. // Don't remove the entry ourselves - see JGRP-1457. } if(key < next_execution_time || no_tasks.compareAndSet(true, false)) { if(key >= next_execution_time) key=0L; taskReady(key); } return retval; }