private void reschedule() { //All access to nextRunTime & runCount under lock. long interval; synchronized (timeLock) { nextRunTime = start + (initialDelay + period * runCount); runCount++; interval = Math.max(0, nextRunTime - System.currentTimeMillis()); } boolean canContinue = !cancelled.get() && !Thread.currentThread().isInterrupted(); if (canContinue) { t.schedule(interval); } }
public void run() { synchronized (m) { if (o != null) { //System.err.println("Expire " + k); // how long we've really been idle long unused = System.currentTimeMillis() - touched; if (unused > (TIMEOUT / 2)) { o = null; touched = 0; } else { task.schedule(TIMEOUT - (int) unused); } } else { // clean up map ref, we are dead //System.err.println("Die " + k); m.remove(k); } } }
public T get() { synchronized (m) { if (o == null) { o = super.get(); } if (o != null) { // touch me //System.err.println("Touch " + k); if (touched == 0) { task.schedule(TIMEOUT); } touched = System.currentTimeMillis(); return o; } else { return null; } } } }
/** * Notify this AsynchChildren that it should reconstruct its children, * calling <code>provider.asynchCreateKeys()</code> and setting the * keys to that. Call this method if the list of child objects is known * or likely to have changed. * @param immediate If true, the keys are updated synchronously from the * calling thread. Set this to true only if you know that updating * the keys will <i>not</i> be an expensive or time-consuming operation. */ public void refresh(boolean immediate) { immediate &= !EventQueue.isDispatchThread(); logger.log (Level.FINE, "Refresh on {0} immediate {1}", new Object[] //NOI18N { this, immediate }); if (logger.isLoggable(Level.FINEST)) { logger.log (Level.FINEST, "Refresh: ", new Exception()); //NOI18N } if (immediate) { boolean done; List <T> keys = new LinkedList <T> (); do { done = factory.createKeys(keys); } while (!done); setKeys (keys); } else { task.schedule (0); } }
protected @Override void addNotify() { logger.log (Level.FINER, "addNotify on {0}", new Object[] { this }); if ((!initialized && task.isFinished()) || cancelled) { cancelled = false; Node n = factory.getWaitNode(); if (n != null) { setKeys (new Object[] { n }); } task.schedule(0); } }
refreshTask.schedule(0); LOG.fine("refreshAll - scheduled"); //NOI18N
t.schedule(ms); } else { refreshTime = 0;
private ScheduledFuture<?> scheduleFixed (Runnable command, long initialDelay, long period, TimeUnit unit, boolean fixedDelay) { Parameters.notNull("unit", unit); //NOI18N Parameters.notNull("command", command); //NOI18N if (period < 0) { throw new IllegalArgumentException ("Negative delay: " + period); //NOI18N } if (initialDelay < 0) { throw new IllegalArgumentException ("Negative initialDelay: " //NOI18N + initialDelay); } if (stopped) { throw new RejectedExecutionException("Request Processor already " + //NOI18N "stopped"); //NOI18N } long initialDelayMillis = TimeUnit.MILLISECONDS.convert(initialDelay, unit); long periodMillis = TimeUnit.MILLISECONDS.convert(period, unit); TaskFutureWrapper wrap = fixedDelay ? new FixedDelayTask(command, initialDelayMillis, periodMillis) : new FixedRateTask(command, initialDelay, periodMillis); Task t = create(wrap); wrap.t = t; t.cancelled = wrap.cancelled; t.schedule (initialDelayMillis); return wrap; }
/** * {@inheritDoc} * <p/> * <b>Note:</b> If the passed {@link java.util.concurrent.Callable} implements * {@link org.openide.util.Cancellable}, then that object's {@link org.openide.util.Cancellable#cancel()} * method will be called if {@link java.util.concurrent.Future#cancel(boolean)} is invoked. * If <code>Cancellable.cancel()</code> returns false, then <i>the job will <u>not</u> be * cancelled</i>. * @since org.openide.util 8.2 */ @Override public <T> Future<T> submit(Callable<T> task) { Parameters.notNull("task", task); //NOI18N if (stopped) { throw new RejectedExecutionException("Request Processor already " + //NOI18N "stopped"); //NOI18N } RPFutureTask<T> result = new RPFutureTask<T>(task); Task t = create(result); result.setTask(t); t.schedule(0); return result; } /**
/** * {@inheritDoc} * @since org.openide.util 8.2 */ @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { Parameters.notNull("command", command); //NOI18N Parameters.notNull("unit", unit); //NOI18N if (delay < 0) { throw new IllegalArgumentException ("Negative delay: " + delay); } if (stopped) { throw new RejectedExecutionException("Request Processor already stopped"); //NOI18N } long delayMillis = TimeUnit.MILLISECONDS.convert(delay, unit); ScheduledRPFutureTask<Void> result = new ScheduledRPFutureTask<Void>(command, null, delayMillis); Task t = create(result); result.setTask(t); t.schedule(delayMillis); return result; } /**
/** * {@inheritDoc} * <b>Note:</b> If the passed {@link java.lang.Runnable} implements * {@link org.openide.util.Cancellable}, then that object's {@link org.openide.util.Cancellable#cancel()} * method will be called if {@link java.util.concurrent.Future#cancel(boolean)} is invoked. * If <code>Cancellable.cancel()</code> returns false, then <i>the job will <u>not</u> be * cancelled</i>. * @since org.openide.util 8.2 */ @Override public <T> Future<T> submit(Runnable task, T predefinedResult) { Parameters.notNull("task", task); //NOI18N if (stopped) { throw new RejectedExecutionException("Request Processor already " + //NOI18N "stopped"); //NOI18N } RPFutureTask<T> result = new RPFutureTask<T>(task, predefinedResult); Task t = create(result); result.setTask(t); t.schedule(0); return result; }
/** * {@inheritDoc} * @since org.openide.util 8.2 */ @Override public <T> ScheduledFuture<T> schedule(Callable<T> callable, long delay, TimeUnit unit) { Parameters.notNull("unit", unit); //NOI18N Parameters.notNull("callable", callable); //NOI18N if (delay < 0) { throw new IllegalArgumentException ("Negative delay: " + delay); } if (stopped) { throw new RejectedExecutionException("Request Processor already " + //NOI18N "stopped"); //NOI18N } long delayMillis = TimeUnit.MILLISECONDS.convert(delay, unit); ScheduledRPFutureTask<T> result = new ScheduledRPFutureTask<T>(callable, delayMillis); Task t = create(result); result.setTask(t); t.schedule(delayMillis); return result; }
public void run() { try { if (root == null) { return; } /** JarFile was modified => parse it and refresh existing FileObjects*/ if (root.lastModified() != lastModification) { parse(true); } } finally { /** reschedule watcherTask*/ Task w = watcherTask; if (w != null) { w.schedule(checkTime); } } } };
/** This methods asks the request processor to start given * runnable after <code>timeToWait</code> milliseconds. Given priority is assigned to the * request. <p> * For request relaying please consider: * <pre> * post(run, timeToWait, Thread.currentThread().getPriority()); * </pre> * * @param run class to run * @param timeToWait to wait before execution * @param priority the priority from {@link Thread#MIN_PRIORITY} to {@link Thread#MAX_PRIORITY} * @return the task to control the request */ public Task post(final Runnable run, int timeToWait, int priority) { RequestProcessor.Task task = new Task(run, priority); task.schedule(timeToWait); return task; }
/** * Create a soft reference with timeout. * The supplied map serves double duty as a synchronization lock * for the reference's state changes. * @param o the referent * @param m a map in which this reference may serve as a value * @param k the key whose value in <code>m</code> may be this reference */ public TimedSoftReference(T o, Map m, Object k) { super(o, Utilities.activeReferenceQueue()); this.o = o; this.m = m; this.k = k; task = RP.create(this); task.schedule(TIMEOUT); }
private void reschedule() { nextRunTime.set(System.currentTimeMillis() + period); if (!fini()) { t.schedule((int) period); } } }
void dispatchEvent(boolean async, Collection<Runnable> postNotify) { if (async) { q.offer(this); task.schedule(300); } else { dispatchEventImpl(fcl, fe, operation, postNotify); } }
/** (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) { schedule((long) delay); }