Java 定时器的问题
我在计时器方面遇到了一个奇怪的问题...在 NetBeans 中测试时,我的计时器工作正常,但是一旦我直接从终端(Ubuntu 10.4)编译并运行,应该每分钟发生的任务就会执行一次,并且永远不会执行再次执行...
这是我的代码:
public static void main(String[] args) throws SQLException
{
// schedule db update task to occur every 15 mins
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask ()
{
@Override public void run()
{
doUpdate();
}
} , 0, updateInterval * 1000 * 60 );
System.out.print("Starting auto update @ ");
// schedule cpu usage check to occur every 1 min
Timer cpu = new Timer();
cpu.scheduleAtFixedRate(new TimerTask ()
{
@Override public void run()
{
getCPU();
}
} , 0, cpuUpdateInterval * 1000 * 60 );
}
我做错了什么吗?
I am having a weird problem with timers... My Timer works correctly when testing in NetBeans, but as soon as I compile and run directly from the terminal (Ubuntu 10.4), the task that is supposed to occur every minute executes once and never executes again...
Here is my code:
public static void main(String[] args) throws SQLException
{
// schedule db update task to occur every 15 mins
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask ()
{
@Override public void run()
{
doUpdate();
}
} , 0, updateInterval * 1000 * 60 );
System.out.print("Starting auto update @ ");
// schedule cpu usage check to occur every 1 min
Timer cpu = new Timer();
cpu.scheduleAtFixedRate(new TimerTask ()
{
@Override public void run()
{
getCPU();
}
} , 0, cpuUpdateInterval * 1000 * 60 );
}
Is there something that I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
getCPU()
是做什么的?如果它正在运行 JNA/JNI 代码或外部库,则可能您的命令行设置中缺少该库。What does
getCPU()
do? If it is running JNA/JNI code or an external library, maybe you are missing the library from your command line settings.通过这段代码,
我得到了预期的结果:
With this code,
I got the expected results: