public class test1{
public static void main(String[] args) {
//查看三个线程运行情况
MyThread mt = new MyThread();
mt.start();
MyThread1 mt1 = new MyThread1();
mt1.start();
MyThread2 mt2 = new MyThread2();
mt2.start();
}
}
class MyThread extends Thread{//内部类方式
@Override
public void run() {
while(true) {
System.out.println("11");
try {
Thread.sleep(1000 * 10);// 每10秒向数据同步一次
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class MyThread1 extends Thread{
@Override
public void run() {
while(true) {
System.out.println("22");
try {
Thread.sleep(1000 * 5);// 每10秒向数据同步一次
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class MyThread2 extends Thread{
@Override
public void run() {
while(true) {
System.out.println("33");
}
}
}
简单多线程记录
最新推荐文章于 2024-07-24 17:27:32 发布