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?
With this code,
I got the expected results: