sleep(long millis) 线程睡眠 millis 毫秒
使用sleep方法可以避免cpu空转,防止cpu占用率过高。
public static void main(String[] args) {
while (true) {
// you code...
try {
Thread.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}