java中实现多线程主要有四种方式:继承Thread类
一,继承Thread类,重写run方法
public class ThreadTest {
//主线程
public static void main(String[] args) {
MyThread1 myThread1 = new MyThread1();
MyThread2 myThread2 = new MyThread2();
myThread1.start();
myThread2.start();
System.out.println("我是主线程");
}
}
public class MyThread1 extends Thread{
@Override
public void run() {
System.out.println("我是线程1");
}
}
public class MyThread2 extends Thread{
@Override
public void run() {
System.out.println("我是线程2");
}
}
标签:Java,Thread,System,run,多线程,public,四种,out
From: https://www.cnblogs.com/tanhongwei/p/16601651.html