这是代码:
timer.schedule(new TimerTask()
{
public void run()
{
synchronized(this)
{
try
{
// System.out.println(" ITERATION = ");
pachubeCLI.update(78164);
}
catch (PachubeException e)
{
// If an exception occurs it will print the error message from the
// failed HTTP command
System.err.println(e.errorMessage);
}
catch (IOException e)
{
System.err.println(e);
}
}
}
}, 0, 5*1000);
我可以说代码基本上是用于使用Timer
类的对象来安排操作。schedule
根据 eclipse,传递给该方法的参数是(TimerTask task,long delay, long period)
. 但是看看这段代码,整个代码块被作为第一个参数而不是对TimerTask
类的引用传递。我以前从未见过这样的方法。这里到底发生了什么?
一些背景:该对象的schedule
方法Timer
被用于定期更新 Xively(以前是 COSM(以前是 pachube))上的提要。
另外我不知道哪个标签描述了这里发生的事情。如果你这样做,请添加它或发表评论。