Java 多线程(sleep)
2021-06-04 03:03
标签:ext 释放 意思 package row sys pac mil 休眠 ??线程休眠的意思, Thread.sleep(毫秒数); ??sleep()会产生InterruptedException异常; ??休眠时间达到后线程进入就绪状态. ??sleep()可以用来模拟网络延迟,倒计时等. ??每一个对象都有一把锁, sleep()不会释放锁. Java 多线程(sleep) 标签:ext 释放 意思 package row sys pac mil 休眠 原文地址:https://www.cnblogs.com/lvzl/p/14665745.htmlpackage com.smile.test.thread;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestSleep {
public static void main(String[] args) throws InterruptedException {
Daojishi();
getSystemTime();
}
private static void Daojishi() throws InterruptedException {
int i = 10;
while (i>=0){
Thread.sleep(1000);
System.out.println(i--);
}
}
private static void getSystemTime () throws InterruptedException {
for (int i = 0; i