public static void main(String[] args) throws IOException {
MYThread mt = new MYThread();
MYRunnale mr = new MYRunnale();
mt.start();
mr.run();
}
class MYThread extends Thread{
public void run() {//重写原Thread中的run方法
for(int i = 0;i < 100000; i++) {
System.out.println("一");
}
}
}
class MYRunnale implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
for(int i = 0;i < 100000; i++) {
System.out.println("主线程");
}
}
}
运行结果:
可以看到两个线程是交替运行的.