JavaSE_线程_线程睡眠时间:2022-10-05 17:30:45 最近自学Java线程相关知识,将自己学的东西记录一下,以后经常拿出来复习一下,防止忘记。 public class ThreadSleep { public static void main(String[] args) { Thread thread = new Thread(new MyThread()); thread.start(); } } class MyThread implements Runnable { // 变量 int i; @Override public void run() { while (true) { System.out.println("Hello World" + i++); try { // 线程睡眠 Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } // 当i的值累积到50,跳出循环 if (i == 50) { break; } } } }