feilv

public class ThreadTest {
public static void main(String[] args) {
MyThread1 thread1 = new MyThread1();
thread1.start();
MyThread2 thread2 = new MyThread2();
Thread th = new Thread(thread2);
th.start();
}
}
class MyThread1 extends Thread {
public void run() {
while (true) {
System.out.println("this is thread1.");
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
}
class MyThread2 implements Runnable {
public void run() {
while (true) {
System.out.println("this is thread2.");
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
}

分类:

技术点:

相关文章:

  • 2021-12-16
  • 2021-11-17
  • 2021-10-02
  • 2022-12-23
  • 2022-02-09
  • 2021-11-17
  • 2022-02-09
  • 2022-12-23
猜你喜欢
  • 2021-11-07
  • 2021-07-29
  • 2021-11-01
  • 2022-12-23
相关资源
相似解决方案