Demo04_sleep.java 749 B

1234567891011121314151617181920212223242526272829303132
  1. package J20250730;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Demo04_sleep
  6. * @description
  7. * @create 2025/7/30
  8. */
  9. public class Demo04_sleep {
  10. public static void main(String[] args) {
  11. Runnable run1=()->{
  12. for (int i = 0; i < 1000; i++) {
  13. if (i==756) {
  14. try {
  15. Thread.sleep(1);
  16. } catch (InterruptedException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. System.out.println(Thread.currentThread().getName()+"->"+i);
  21. }
  22. };
  23. Thread t1=new Thread(run1,"线程1");
  24. Thread t2=new Thread(run1,"线程2");
  25. t1.start();
  26. t2.start();
  27. }
  28. }