由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Why System.currentTimeMillis() is later then TimerTask.scheduledExecutionTime() in some cases?
相关主题
Timer and TimerTask问个系统问题 (转载)
java.util.timer的TimerTask有priority吗?java: use vector to shuffle a deck of Card 问题 (转载)
这个Timer不退出是怎么回事儿?java如何keep大数组在内存中?
简单的schedule job, 你们用什么Re: 有用netbeans的吗?
怎么在application实现delay?where to execute java program?
question on ant task[合集] How to get all classes under a package?
htmlunit及多线程问题[合集] TexPen question
web app 每天更新数据一次array to list
相关话题的讨论汇总
话题: fixed话题: delay话题: why话题: timertask
进入Java版参与讨论
1 (共1页)
l*****b
发帖数: 82
1
I have a TimerTask to trigger the transaction at every hours (e.g. 1:00, 2:
00, 3:00, etc). As to the instruction of method TimerTask.
scheduledExecutionTime(), I have the following codes to skip some overdue
tasks:
public void run() {
if (System.currentTimeMillis() - scheduledExecutionTime() >= 1000)
return; // 1 s delay, Too late; skip this execution.
// Perform the task
}
But I encounter some strange issue which this code works in one of my server
box but rather than the other server box (whi
A**o
发帖数: 1550
2
my guess is when your server is idle, everything was swapped to disk by the
system. then 1s delay is not abnormal. maybe you want to have 5min preload
event to make sure your jboss is active and in the memory?
and your workaround works. that's all it matters.
F****n
发帖数: 3271
3
It's has nothing to do with System.currentTimeMillis(). More likely, it is
because of your Timer. Check the Timer you are using. For example, are you using fixed-delay or fixed-rate scheduling? java.util.Timer.schedule is fixed-delay by default, so it will count ONLY AFTER the last execution completes.
b******y
发帖数: 9224
4

using fixed-delay or fixed-rate scheduling? java.util.Timer.schedule is
fixed-delay by default, so it will count ONLY AFTER the last execution
completes.
Wow, makes sense.

【在 F****n 的大作中提到】
: It's has nothing to do with System.currentTimeMillis(). More likely, it is
: because of your Timer. Check the Timer you are using. For example, are you using fixed-delay or fixed-rate scheduling? java.util.Timer.schedule is fixed-delay by default, so it will count ONLY AFTER the last execution completes.

g*****g
发帖数: 34805
5
Use quartz, it's more powerful than java timer.

server

【在 l*****b 的大作中提到】
: I have a TimerTask to trigger the transaction at every hours (e.g. 1:00, 2:
: 00, 3:00, etc). As to the instruction of method TimerTask.
: scheduledExecutionTime(), I have the following codes to skip some overdue
: tasks:
: public void run() {
: if (System.currentTimeMillis() - scheduledExecutionTime() >= 1000)
: return; // 1 s delay, Too late; skip this execution.
: // Perform the task
: }
: But I encounter some strange issue which this code works in one of my server

b******y
发帖数: 9224
6
I still like the Linux cron.
l*****b
发帖数: 82
7

using fixed-delay or fixed-rate scheduling? java.util.Timer.schedule is
fixed-delay by default, so it will count ONLY AFTER the last execution
completes.
Thanks, Foxman. I use fixed-rate scheduling as the following method:
public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period)
Tasks are triggered at every hour per day.
I found the difference of System.currentTimeMillis() and
scheduledExecutionTime() increased gradually by 500ms and stops at about
12000ms and keep stable. I

【在 F****n 的大作中提到】
: It's has nothing to do with System.currentTimeMillis(). More likely, it is
: because of your Timer. Check the Timer you are using. For example, are you using fixed-delay or fixed-rate scheduling? java.util.Timer.schedule is fixed-delay by default, so it will count ONLY AFTER the last execution completes.

m******t
发帖数: 2416
8

Heh, nothing beats cron indeed.
That said, if your deployment environment isn't entirely under
your control, it often becomes a political struggle with another
team over cronjobs.

【在 b******y 的大作中提到】
: I still like the Linux cron.
1 (共1页)
进入Java版参与讨论
相关主题
array to list怎么在application实现delay?
Tomcat Servlet: synchronized vs non-synchronized methodsquestion on ant task
新手问题。htmlunit及多线程问题
问一个Many to Many的设计问题web app 每天更新数据一次
Timer and TimerTask问个系统问题 (转载)
java.util.timer的TimerTask有priority吗?java: use vector to shuffle a deck of Card 问题 (转载)
这个Timer不退出是怎么回事儿?java如何keep大数组在内存中?
简单的schedule job, 你们用什么Re: 有用netbeans的吗?
相关话题的讨论汇总
话题: fixed话题: delay话题: why话题: timertask