本文整理了Java中java.util.Timer.schedule()
方法的一些代码示例,展示了Timer.schedule()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timer.schedule()
方法的具体详情如下:
包路径:java.util.Timer
类名称:Timer
方法名:schedule
[英]Schedule a task for single execution after a specified delay.
[中]在指定的延迟后为单个执行计划任务。
代码示例来源:origin: pedrovgs/AndroidWiFiADB
public void run() {
new Timer().schedule(new TimerTask() {
@Override public void run() {
boolean refreshRequired = androidWifiADB.refreshDevicesList();
if (refreshRequired) {
updateUi();
}
}
}, 0, INTERVAL_REFRESH_DEVICES);
}
});
代码示例来源:origin: redisson/redisson
/**
* Schedules prune.
*/
public void schedulePrune(long delay) {
if (pruneTimer != null) {
pruneTimer.cancel();
}
pruneTimer = new Timer();
pruneTimer.schedule(
new TimerTask() {
@Override
public void run() {
prune();
}
}, delay, delay
);
}
代码示例来源:origin: FudanNLP/fnlp
public StopWords(String dicPath1,boolean b){
this.dicPath = dicPath1;
// 定期监视文件改动
Timer timer = new Timer(true);
timer.schedule(new TimerTask() {
@Override
public void run() {
read(dicPath);
}
}, new Date(System.currentTimeMillis() + 10000), 24*60*60*1000);
}
/**
代码示例来源:origin: stackoverflow.com
@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();
代码示例来源:origin: stackoverflow.com
System.out.println("Generating report");
Timer timer = new Timer();
Calendar date = Calendar.getInstance();
date.set(
date.set(Calendar.MILLISECOND, 0);
timer.schedule(
new ReportGenerator(),
date.getTime(),
代码示例来源:origin: marytts/marytts
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();
}
}
}
});
代码示例来源:origin: apache/metron
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() {
代码示例来源:origin: apache/geode
/**
* @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);
}
代码示例来源:origin: openmrs/openmrs-core
} else {
getTimer(taskDefinition).schedule(schedulerTask, nextTime);
getTimer(taskDefinition).schedule(schedulerTask, new Date());
代码示例来源:origin: apollographql/apollo-android
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);
}
}
代码示例来源:origin: apache/hive
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);
}
}
}
代码示例来源:origin: naver/ngrinder
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();
代码示例来源:origin: org.eclipse.jetty/jetty-util
public void schedule ()
{
if (_running)
{
if (_timer!=null)
_timer.cancel();
if (_task!=null)
_task.cancel();
if (getScanInterval() > 0)
{
_timer = newTimer();
_task = newTimerTask();
_timer.schedule(_task, 1010L*getScanInterval(),1010L*getScanInterval());
}
}
}
/**
代码示例来源:origin: k9mail/k-9
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);
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
if (timer != null) {
final CountDownLatch latch = new CountDownLatch(1);
timer.schedule(new TimerTask() {
@Override
public void run() {
LOGGER.log(Level.FINE, "Triggers shut down successfully");
} else {
timer.cancel();
LOGGER.log(Level.INFO, "Gave up waiting for triggers to finish running");
代码示例来源:origin: stackoverflow.com
Date now = new Date();
if(!TextUtils.isEmpty(target))
timer = new Timer();
timer.schedule(new MonitoringTimerTask(), 500, SERVICE_PERIOD);
timer.cancel();
timer.purge();
timer = null;
代码示例来源:origin: stackoverflow.com
static int cnt=0;
public ArrayList<RadioButton> buttonArray = new ArrayList<RadioButton>();
private Timer timer = new Timer();
timer.schedule(new MyTimerTask(), 1000,2000);
System.out.println(cnt);
代码示例来源:origin: marytts/marytts
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();
}
}
}
});
代码示例来源:origin: zccodere/study-imooc
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);
}
代码示例来源:origin: stackoverflow.com
Timer timer = new Timer();
timer.schedule(new TimerTask() {
,new Date(), 3000L);
内容来源于网络,如有侵权,请联系作者删除!