循环执行速度控制 [英] Loop execution speed control

查看:85
本文介绍了循环执行速度控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以控制循环的执行速度? 我有一个30000个步骤的循环中运行的仿真.我想可视化该循环中发生的事情,并在可能的情况下控制其运行时的执行速度.有什么想法我该怎么做吗?

Is there a way to control the speed of execution of a loop ? I have a simulation that runs in a loop of 30000 steps. I want to visualise whats happening in that loop and if possible control the speed of execution while its running. Any ideas how i could do that ?

推荐答案

在循环内放入Thread.sleep()语句.请注意,尽管您必须处理异常.

Put a Thread.sleep() statement inside the loop. Beware though that you have to handle the exception.

for(int i = 0; i < 30000; i++) {

    ...

    try {
        Thread.sleep(100);
    }
    catch(InterruptedException e) {
        // do something with e
    }
}

这篇关于循环执行速度控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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