1.实现奇数和偶数的交叉打印
2.打印时间间隔1秒
public class testthread02 {
public static void main(string[] args) {
thread t1 = new eventhread();
thread t2 = new eventhread();
t1.setname("奇数线程");
t2.setname("偶数线程");
t1.start();
t2.start();
}
}
class eventhread extends thread{
private static int num = 0;
public void run() {
while (true) {
synchronized (thread.class) {
system.out.println(getname() + ":" + ++num);
try {
thread.sleep(1000);
thread.class.notify();
thread.class.wait();
} catch (interruptedexception e) {
e.printstacktrace();
}
}
}
}
}
如对本文有疑问, 点击进行留言回复!!
第三次学JAVA再学不好就吃翔(part88)--ArrayList嵌套ArrayList
使用ffmpeg视频切片并加密和视频AES-128加密后播放
JAVA程序设计:最长重复子串(LeetCode:1044)
LiveGBS国标GB/T28181云端录像分布式录像存储自动清理时移回看录像下载播放
网友评论