@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();
public void actionPerformed(ActionEvent e) { synchronized (clip) { if (clip.isActive()) { System.err.println("Stopping clip."); clip.stop(); } else { System.err.println("Rewinding clip."); if (Double.isNaN(positionCursor.x)) { // no cursor, play from start clip.setFramePosition(0); } else { // play from cursor position clip.setFramePosition(X2indexX(positionCursor.x)); } if (!Double.isNaN(rangeCursor.x)) { // range set? System.err.println("Setting timer task"); int endFrame = X2indexX(rangeCursor.x); timer.schedule(new ClipObserver(clip, endFrame), 50, 50); } System.err.println("Starting clip."); clip.start(); } } } });
System.out.println("Consumer Group: " + groupId); kafkaConfig.put(ConsumerConfig.GROUP_ID_CONFIG, groupId); if(LoadOptions.KAFKA_CONFIG.has(cli)) { System.out.println("Thread pool size: " + numThreads); pool = Executors.newFixedThreadPool(numThreads); Optional<Object> eps = evaluatedArgs.get(LoadOptions.EPS); long monitorDelta = (long) evaluatedArgs.get(LoadOptions.MONITOR_DELTA).get(); if((eps.isPresent() && outputTopic.isPresent()) || monitorTopic.isPresent()) { Timer timer = new Timer(false); long startTimeMs = System.currentTimeMillis(); if(outputTopic.isPresent() && eps.isPresent()) { List<String> templates = (List<String>)evaluatedArgs.get(LoadOptions.TEMPLATE).get(); if(templates.isEmpty()) { System.out.println("Empty templates, so nothing to do."); return; if(timeLimit.isPresent()) { System.out.println("Ending in " + timeLimit.get() + " ms."); timer.schedule(new TimerTask() { @Override public void run() {
/** * @see Timer#schedule(TimerTask, long) */ public void schedule(SystemTimerTask task, long delay) { checkCancelled(); if (logger.isTraceEnabled()) { Date tilt = new Date(System.currentTimeMillis() + delay); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); logger.trace("SystemTimer#schedule (long): {}: expect task {} to fire around {}", this, task, sdf.format(tilt)); } timer.schedule(task, delay); }
void schedule(final int taskId, final Runnable task, long delay) { TimerTask timerTask = new TimerTask() { @Override public void run() { try { task.run(); } finally { cancelTask(taskId); } } }; synchronized (this) { TimerTask previousTimerTask = tasks.put(taskId, timerTask); if (previousTimerTask != null) { previousTimerTask.cancel(); } if (timer == null) { timer = new Timer("Subscription SmartTimer", true); } timer.schedule(timerTask, delay); } }
public void go() { LOG.info("Running ReporterTask every " + notificationInterval + " miliseconds."); rpTimer = new Timer(true); ReporterTask rt = new ReporterTask(reporter); rpTimer.scheduleAtFixedRate(rt, 0, notificationInterval); if (timeout > 0) { srpTimer = new Timer(true); StopReporterTimerTask srt = new StopReporterTimerTask(rt); srpTimer.schedule(srt, timeout); } } }
final Timer timer = new Timer(true); timer.schedule(reportTimerTask, reportToConsoleInterval, reportToConsoleInterval); m_terminalLogger.info("This test will shut down after {} ms", duration); timer.schedule(shutdownTimerTask, duration); reportTimerTask.cancel(); shutdownTimerTask.cancel(); m_logger.info(statistics.toString()); timer.cancel();
private void raiseNotification() { if (timer != null) { synchronized (timer) { if (timerTask != null) { timerTask.cancel(); timerTask = null; } timerTask = new TimerTask() { @Override public void run() { if (startTime != null) { Long endTime = SystemClock.elapsedRealtime(); Timber.i("TracingWakeLock for tag %s / id %d: has been active for %d ms, timeout = %d ms", tag, id, endTime - startTime, timeout); } else { Timber.i("TracingWakeLock for tag %s / id %d: still active, timeout = %d ms", tag, id, timeout); } } }; timer.schedule(timerTask, 1000, 1000); } } } }
public void actionPerformed(ActionEvent e) { synchronized (clip) { if (clip.isActive()) { System.err.println("Stopping clip."); clip.stop(); } else { System.err.println("Rewinding clip."); if (Double.isNaN(positionCursor.x)) { // no cursor, play from start clip.setFramePosition(0); } else { // play from cursor position clip.setFramePosition(X2indexX(positionCursor.x)); } if (!Double.isNaN(rangeCursor.x)) { // range set? System.err.println("Setting timer task"); int endFrame = X2indexX(rangeCursor.x); timer.schedule(new ClipObserver(clip, endFrame), 50, 50); } System.err.println("Starting clip."); clip.start(); } } } });
public static void main(String[] args){ Timer timer = new Timer(); // 获取当前时间 Calendar calendar = Calendar.getInstance(); SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("Current time is : " + sf.format(calendar.getTime())); DancingRobot dancingRobot = new DancingRobot(); WaterRobot waterRobot = new WaterRobot(timer); timer.schedule(dancingRobot,calendar.getTime(),2000L); timer.scheduleAtFixedRate(waterRobot,calendar.getTime(),1000L); }