Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要每隔很短的时间执行一次我的代码,例如每 100 毫秒(甚至更少)。
我想我可以生成一个线程并在其中添加一个无限循环,但我认为这不好。
您可以使用Timer和TimerTask。
final Timer timer = new Timer(); final int period = 100; final int delay = 0; timer.schedule(new TimerTask() { @Override public void run() { log.debug("executing something"); } }, delay, period);