@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); } } });
/** * @param client Client. */ private void suspendClientMetricsUpdate(Ignite client) { assert client.cluster().localNode().isClient(); ClientImpl impl = U.field(client.configuration().getDiscoverySpi(), "impl"); Timer timer = U.field(impl, "timer"); timer.cancel(); System.out.println("Metrics update message suspended"); } }
@Override public void run() { System.out.println(new Date() + " running ..."); timer = new Timer(); timer.schedule(new EchoTask(), 0, 1000); System.out.println("initializing ..."); System.out.println("starting ..."); main(null); System.out.println("stopping ..."); if (timer != null) { timer.cancel();
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;
private void timerUpdate() { timer.cancel(); if (timer_run && timer_msec > 0) { timer.scheduleAtFixedRate(new Flusher(), 0, timer_msec); } }
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
@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(); } }
private void mergeData() throws IOException { final Timer timer = new Timer("javamelody-datamerge", true); try { JRobin.initBackendFactory(timer); final List<File> directories = new ArrayList<>(listFiles(storageDirectory)); for (final Iterator<File> it = directories.iterator(); it.hasNext();) { if (!it.next().isDirectory()) { it.remove(); } } if (directories.isEmpty()) { throw new IllegalArgumentException( "No subdirectories found in " + storageDirectory); } mergeDirectories(directories); } finally { timer.cancel(); } }
@Override public void run() { synchronized(this) { if (debugMode) { String threadName = Thread.currentThread().getName(); System.out.println( threadName + " - RecordSendTask run, " + roundCounter + " round, " + recordsCounter + " records sent"); } if (isRecordValid() && isRoundValid()) { // Send records to Kafka long sentRecords = sender.send(topic, recordsPerInterval, debugMode); // Update counter roundCounter++; recordsCounter.getAndAdd(sentRecords); } else { if(!stopped) { sender.close(); timer.cancel(); timer.purge(); stopped = true; // exit timer thread System.out.println("DataGenerator stop, " + roundCounter + " round, " + recordsCounter + " records sent"); } } } }
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(); }