Java 8 TimerTask - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TimerTask class.

This code example shows how to use the following methods:run
    if (isCanceled()) { 
      cancel();
      return; 
    } 
    try { 
      task.run();
    } catch (Throwable thrown) {
      handleException(thrown);
    } 
  } 
 
  private boolean isCanceled() { 
    try { 
      int state = Preconditions.checkNotNull(field("state").ofType(int.class).in(task).get());
      return state == CANCELED;
    } catch (RuntimeException e) {
      handleException(e);
    } 
    return false; 
  } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
		timer.scheduleAtFixedRate(task, delay, interval);
	} 
 
	protected void removeTask(TimerTask task)
	{ 
		task.cancel();
		timer.purge();
	} 
 
	protected void kill() 
	{ 
		timer.cancel();
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
    } 
 
    public static synchronized void cancel(Runnable task) {
        TimerTask ticket = TIMER_TASKS.remove(task);
        if (ticket != null) {
            ticket.cancel();
            CLOCK_DAEMON.purge();//remove cancelled TimerTasks
        } 
    } 
 
    public static void executeAfterDelay(final Runnable task, long redeliveryDelay) {
        TimerTask timerTask = new SchedulerTimerTask(task);
        CLOCK_DAEMON.schedule(timerTask, redeliveryDelay);
    } 
 
    public static void shutdown() { 
        CLOCK_DAEMON.cancel();
    } 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
 
    public void StopWakerMonitor() 
    {         
        if ( mWakeTask != null )
        { 
            mWakeTask.cancel();
            mWakeTask = null;
        } 
    } 
 
    /************************************************************************************************* 
     *================================= Private interface section ================================= 
     */ 
 
    /************************************************************************************************* 
     *================================= Data members section ================================= 
     *  
     */ 
     
    public static final long WAKE_REFRESH_PERIOD_DEFAULT = 9999L;		// Assume the 10 sec is the minimal screen timeout
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:run
    if (isCanceled()) { 
      cancel();
      return; 
    } 
    try { 
      task.run();
    } catch (Throwable thrown) {
      handleException(thrown);
    } 
  } 
 
  private boolean isCanceled() { 
    try { 
      int state = Preconditions.checkNotNull(field("state").ofType(int.class).in(task).get());
      return state == CANCELED;
    } catch (RuntimeException e) {
      handleException(e);
    } 
    return false; 
  } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:scheduledExecutionTime
    } 
 
    /** Checks that scheduledExecutionTime returns a "recent" time. */ 
    void checkScheduledExecutionTime(TimerTask task) { 
        long t = System.currentTimeMillis() 
            - task.scheduledExecutionTime(); 
        check(t >= 0 && t < 1000 * 600); 
    } 
 
    void test(String[] args) throws Throwable { 
        for (int how=0; how<4; how++) { 
            final CountDownLatch done = new CountDownLatch(1); 
            final AtomicInteger count = new AtomicInteger(0); 
            final Timer timer = new Timer(); 
            final TimerTask task = new TimerTask() { 
                @Override 
                public void run() { 
                    checkScheduledExecutionTime(this); 
                    count.incrementAndGet(); 
                    done.countDown(); 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
        Log.e("Download", "ondestroy");
 
        getTrafficStats(); // last count 
 
        if (timerTask != null) {
            timerTask.cancel();
        } 
        if (timer != null) {
            timer.cancel();
            timer.purge();
        } 
    } 
 
    private String operatorName;
    private long curTx, curRx, preTx, preRx;
    private NetworkInfo networkInfo;
 
    private void getTrafficStats() { 
 
        curTx = TrafficStats.getUidTxBytes(mUid);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
  synchronized void stop() { 
    if (useAutoFocus) {
      camera.cancelAutoFocus();
    } 
    if (outstandingTask != null) {
      outstandingTask.cancel();
      outstandingTask = null;
    } 
    active = false;
    manual = false;
  } 
 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
		timer.schedule(task, 0, PERIOD);
	} 
 
	private static void stop() { 
		if (!isRunning()) return; 
		task.cancel();
		task = null;
		timer = null;
	} 
 
	private boolean isAutostart() { 
		return getSharedPreferences(this).getBoolean(AUTOSTART, true);
	} 
	 
	private void setAutostart(boolean value) {
		getSharedPreferences(this).edit().putBoolean(AUTOSTART, value).commit();
	} 
	 
	@Override 
	public IBinder onBind(Intent i) {
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:cancel
    /** 
     * {@inheritDoc} 
     */ 
    public void shutdown() { 
        if (samplerTask != null) {
            samplerTask.cancel();
        } 
    } 
 
    /** 
     * Returns the timer task for this sampled counter 
     *  
     * @return the timer task for this sampled counter 
     */ 
    public TimerTask getTimerTask() {
        return this.samplerTask;
    } 
 
    /** 
     * Returns the sampling thread interval in millis 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 TimerTask Questions & Answers:

See Code Examples for Java 8 TimerTask Methods: