-1
A
回答
2
隨着chrylis回答,Timer
類可以適合你。 Here我寫的這個答案可以幫助你。
package perso.tests.timer;
import java.util.Timer;
import java.util.TimerTask;
public class TimerExample extends TimerTask{
Timer timer;
int executionsPerSecond;
public TimerExample(int executionsPerSecond){
this.executionsPerSecond = executionsPerSecond;
timer = new Timer();
long period = 1000/executionsPerSecond;
timer.schedule(this, 200, period);
}
public void functionToRepeat(){
System.out.println(executionsPerSecond);
}
public void run() {
functionToRepeat();
}
public static void main(String args[]) {
System.out.println("About to schedule task.");
new TimerExample(3);
new TimerExample(6);
new TimerExample(9);
System.out.println("Tasks scheduled.");
}
}
3
相關問題
- 1. JavaScript - 每n秒做一件事
- 2. 如何讓每N秒
- 3. 如何每秒做n次?
- 4. 如何在一些毫秒後提高懸停事件?
- 5. c#FileSystemWatcher - 每隔幾秒鐘提高數百個不需要的過多事件
- 6. 在tbody中的每個td上提高jQuery點擊事件
- 7. 推力::序列 - 如何提高每個N元素後一步
- 8. 如何從另一個提高事件
- 9. 我如何編寫「每秒事件」PerformanceCounter?
- 10. 如何監視每秒logstash事件
- 11. 如何每隔x秒在ICS文件中重複事件?
- 12. 如何在STM32 MCU中每通道每n秒讀取幾個ADC接口?
- 13. 安排在java中每秒發生10次事件
- 14. 如何提高Yii中的CComponent事件
- 15. 如何在Thumb上提高DragDelta事件
- 16. 如何提高事件在WP8
- 17. 提高SQLite的每秒更新性能?
- 18. 每秒提高性能刷新項目
- 19. FileSystemWatcher提高多個事件
- 20. 火災事件每秒
- 21. 過濾每第n個事件
- 22. 如何在ios中每n秒獲取位置更新
- 23. 如何在imageview中每n秒鐘更改一次圖像
- 24. 在vb.net我如何提高另一個控件的事件
- 25. 每n毫秒寫一個字符串
- 26. 擊:增加每列n秒
- 27. 更新每n秒QLineEdit值
- 28. 如何提高每運行n分鐘的循環的性能
- 29. Java - 每秒重繪組件?
- 30. 如何提高每個循環
也許,你可以看看使用線程。 – guisantogui
每秒N個事件表示您必須每隔1/N秒觸發一次事件。看看'Thread.sleep();' –
爲此,最好不要使用Thread和Thread.sleep()。 Timer在這種情況下完全符合要求 –