Code example for ScheduledThreadPoolExecutor

Methods: remove, schedule

0
			final long now = System.currentTimeMillis();
			this.nextLogoutInMillis = now + timeOutInMillis;
		} 
		 
		public synchronized void reschedule(long whenInMillis) {
			executor.remove(LogoutChecker.this);
			executor.schedule(LogoutChecker.this, whenInMillis, TimeUnit.MILLISECONDS);
			if (DEBUG) Log.d(LOG_TAG, "timer (re)scheduled at "+whenInMillis);
		} 
 
		public synchronized void run() { 
			if (DEBUG) Log.d(LOG_TAG, "checking logout ...");
			long now = System.currentTimeMillis();
			if (now >= nextLogoutInMillis) {
				logout(); 
			} else { 
				long nextCheckInMillis = nextLogoutInMillis - now;
				reschedule(nextCheckInMillis);
			} 
		}