如何设置每秒重复计数? [英] How can I set while repeat count per second?

查看:85
本文介绍了如何设置每秒重复计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用while循环在程序中重复我的代码.我想每秒重复一次代码1000次.我该怎么办?

I use a while loop to repeat my codes in my program. I want to repeat a code 1000 times per second. How can I do this?

推荐答案

对于某些代码的固定延迟执行,使用 timer对象可能是更好的方法,例如 java.util.Timer javax.swing.Timer ,甚至 AnimationTimer ,具体取决于您正在尝试完成.话虽如此,无法保证频率和1000/s(或1ms的周期)的频率非常快,并且java.util.Timerjavax.swing.Timer不能跟上.

For the fixed-delay execution of some code, it might be a better approach to use a timer object, such as java.util.Timer or javax.swing.Timer, or even AnimationTimer, depending on what you're trying to accomplish. This being said, it's not possible to guarantee a frequency and a frequency of 1000/s (or period of 1ms) is quite fast, and java.util.Timer and javax.swing.Timer won't be able to keep up.

另请参阅:

  • How to use swing timers
  • How to use Java.Util.Timer
  • High Resolution Timer in Java 5

这篇关于如何设置每秒重复计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆