我使用SchduledExecuterService类通过scheduleAtFixedRate()方法重复运行一些代码。
exec.scheduleAtFixedRate(new Runnable() {
public void run() {
//some code
}
}, 1, 1, TimeUnit.SECONDS);问题是,我想根据一个变量,即TimeUnit.SECONDS*num,将TimeUnit参数更改为秒的某一分数;但是该方法不接受long作为参数,只接受固定的TimeUnits。有什么建议吗?
发布于 2019-10-08 23:00:37
你为什么不玩周期参数呢?
long periodInMicroseconds = 16667;
exec.scheduleAtFixedRate(new Runnable() {
public void run() {
//some code
}
}, 0, periodInMicroseconds, TimeUnit.MICROSECONDS);https://stackoverflow.com/questions/58288905
复制相似问题