Java中暂停线程的方法sleep()

    科技2026-04-04  9

    J a v a Java Java中暂停线程的方法 s l e e p ( ) sleep() sleep()

    s l e e p ( ) sleep() sleep()方法:使当前执行的线程在指定的毫秒数内休眠(暂时停止执行)

    注: s l e e p ( ) sleep() sleep()方法执行时会抛出异常 I n t e r r u p t e d E x c e p t i o n InterruptedException InterruptedException 需要使用 t r y   c a t c h try\ catch try catch语句捕捉异常。

    public class Test { public static void main(String[] args) { for (int i = 0; i < 60; i++) { System.out.println(i); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }
    Processed: 0.014, SQL: 9