Refine search
/** * Start the timer to run at fixed intervals. */ @Override public void start() { rotationTimer = new Timer(true); TimerTask task = new TimerTask() { @Override public void run() { rotationTimerTriggered.set(true); } }; rotationTimer.scheduleAtFixedRate(task, interval, interval); }
@Override public void run() { try { if (indexingTimer != null) { indexingTimer.cancel(); } previousDigest = null; indexingTimer = new Timer(); indexingTimer.scheduleAtFixedRate( indexingTask, 0, Constants.APP_INDEXING_SCHEDULE_INTERVAL_MS ); } catch (Exception e) { Log.e(TAG, "Error scheduling indexing job", e); } } });
Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { System.out.println(System.currentTimeMillis()); } }; timer.scheduleAtFixedRate(task, 0, 1000);
int delay = 1000; int period = 1000; timer = new Timer(); interval = Integer.parseInt(secs); System.out.println(secs); timer.scheduleAtFixedRate(new TimerTask() { System.out.println(setInterval()); timer.cancel(); return --interval;
public static void main(String args[]) { int period = 2000; int delay = 2000; Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { // Variables as member variables instead of local variables in main() private double lastPrice = 0; private Price priceObject = new Price(); private double price = 0; public void run() { price = priceObject.getNextPrice(lastPrice); System.out.println(); lastPrice = price; } }, delay, period); }
while (true) { try { System.out.println("Thread reading counter is: " + counter); if (counter == 3) { System.out.println("Counter has reached 3 now will terminate"); timer.cancel();//end the timer break;//end this loop timer = new Timer("MyTimer");//create a new timer timer.scheduleAtFixedRate(timerTask, 30, 3000);//start timer in 30ms to increment counter
public void contextInitialized(ServletContextEvent event) { Timer timer = new Timer(true); timer.scheduleAtFixedRate(new CleanDBTask(), 0, oneHourInMillis); timer.scheduleAtFixedRate(new StatisticsTask(), 0, oneQuartInMillis); }
@Override protected void copyData(InputStream inputStream, OutputStream outputStream) throws IOException { final CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream); Timer timer = new Timer(); try { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { progressListener.updateProgress(countingOutputStream.getCount()); } }, 0, 50); super.copyData(inputStream, countingOutputStream); } finally { timer.cancel(); } }
public void createOutputSimilaritiesTimer(Namespace ns) { int windowSecs = ns.getInt("output_poll_secs"); int timer_ms = windowSecs * 1000; System.out.println("Scheduling at "+timer_ms); outputTimer = new Timer(true); outputTimer.scheduleAtFixedRate(new TimerTask() { public void run() { long time = ItemSimilarityProcessor.this.outputSimilaritiesTime.get(); if (time > 0) { SimpleDateFormat sdf = new SimpleDateFormat("MMMM d, yyyy 'at' h:mm a"); String date = sdf.format(time*1000); System.out.println("getting similarities at "+date); List<JaccardSimilarity> res = streamJaccard.getSimilarity(time); System.out.println("Results size "+res.size()+". Sending Messages..."); sendMessages(res, time); System.out.println("Messages sent"); ItemSimilarityProcessor.this.outputSimilaritiesTime.set(0); } else { System.out.println("Timer: not outputing similarities"); } } }, timer_ms, timer_ms); }
private void runWorkers(ExecutorService executorService) throws InterruptedException { final int numberOfIterations = configuration.getNumberOfIterations(); final int taskCount = numberOfIterations * configuration.getWorkerTasks().length; final CountDownLatch sync = new CountDownLatch(taskCount); final Timer timer = new Timer(); timer.scheduleAtFixedRate(new ProgressReporter(taskCount, sync, configuration.isColor()), 2000, 2000); System.out.println("Generating load. Total tasks: "+taskCount+"... "); for (int i = 1; i <= numberOfIterations; i++) { for (Runnable runnable : configuration.getWorkerTasks()) { executorService.execute(wrap(runnable, sync)); } } sync.await(); timer.cancel(); if(configuration.isColor()) System.out.print(CLEAR_LINE + ANSI_GREEN); System.out.println("Finished generating load."); if(configuration.isColor()) System.out.print(ANSI_RESET); executorService.shutdown(); }
new Timer().scheduleAtFixedRate(task, after, interval);
private synchronized void scheduleHostLBCheckerTask(final long checkInterval) { if (hostLBTimer != null) { hostLBTimer.cancel(); } if (checkInterval > 0L) { s_logger.info("Scheduling preferred host timer task with host.lb.interval=" + checkInterval + "ms"); hostLBTimer = new Timer("Host LB Timer"); hostLBTimer.scheduleAtFixedRate(new PreferredHostCheckerTask(), checkInterval, checkInterval); } }
System.out.println(exchangeSpecification.toString()); Exchange bitcoiniumExchange = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification); Timer timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 10000); // every ten
public static void start() { if (start.compareAndSet(false, true)) { timer = new Timer("AliveKeepingService"); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("I'm alive"); } } }, 1000 * 60 * 10, 1000 * 60 * 10); } }
myTimer = new Timer(); myTimer.scheduleAtFixedRate(new Task(), START_TIME, RETRY_TIME); timerRunning = true; public int onStartCommand(Intent intent, int flags, int startId) { if (!timerRunning) { myTimer = new Timer(); myTimer.scheduleAtFixedRate(new Task(), START_TIME, RETRY_TIME); timerRunning = true; myTimer.cancel();
System.out.println(exchangeSpecification.toString()); Exchange bitcoiniumExchange = ExchangeFactory.INSTANCE.createExchange(exchangeSpecification); Timer timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 10000); // every ten
public static void start() { if (start.compareAndSet(false, true)) { timer = new Timer("AliveKeepingService"); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("I'm alive"); } } }, 1000 * 60 * 10, 1000 * 60 * 10); } }
timer.cancel(); // just in case if (chartInfo.getExampleChartName().startsWith("RealtimeChart01")) { timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 500); } else if (chartInfo.getExampleChartName().startsWith("RealtimeChart02")) { timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 500); } else if (chartInfo.getExampleChartName().startsWith("RealtimeChart03")) { timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 500); } else if (chartInfo.getExampleChartName().startsWith("RealtimeChart04")) { timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 500); } else if (chartInfo.getExampleChartName().startsWith("RealtimeChart05")) { timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 500); } else if (chartInfo.getExampleChartName().startsWith("RealtimeChart06")) { timer = new Timer(); timer.scheduleAtFixedRate(chartUpdaterTask, 0, 500);
import java.util.Timer; import java.util.TimerTask; public class Test { static int counter = 0; public static void main(String[] args) { TimerTask timerTask = new TimerTask() { @Override public void run() { System.out.println("TimerTask executing counter is: " + counter); counter++;//increments the counter } }; Timer timer = new Timer("MyTimer");//create a new Timer timer.scheduleAtFixedRate(timerTask, 30, 3000);//this line starts the timer at the same time its executed } }
/** * Add a limited life time to the Session. * The Session is stoped and remove from agents List after a certain time. * Prevents that network cycles, refreshes a Session forever. * * @param lifetime time in Seconds to kill the Session */ void addLifeTime(long lifetime) { lifetime *= 1000; if (lifeTimer != null) return; lifeTimer = new Timer(); lifeTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { stopAgent(); } }, lifetime, lifetime); }