写的超详细 收藏了~
https://www.jianshu.com/p/87a5f9e41238
package map;
public class thread {
public static void main(String[] args) throws InterruptedException {
// for(int i=0;i<10;i++) {
// System.out.println(Thread.currentThread().getName()+"i="+i);
// }
// TODO Auto-generated method stub
//Thread.sleep(1);
threads st =new threads();
threadB stB=new threadB();
threadc stc=new threadc();
threadc stc2=new threadc();
// 通过new Thread(target , name)方法创建新线程
// new Thread(st ,"新线程1").start();
// new Thread(st ,"新线程2").start();
// new Thread(st ,"新线程3").start();
stc.start();
stc2.start();
}
}
class threads implements Runnable{
private int i;
@Override
public void run() {
// TODO Auto-generated method stub
for(i=0;i<10;i++) {
System.out.println(Thread.currentThread().getName()+"i="+i);
}
}
}
class threadB implements Runnable{
private int i;
@Override
public void run() {
// TODO Auto-generated method stub
for(i=0;i<10;i++) {
System.out.println(Thread.currentThread().getName()+"i="+i);
}
}
}
class threadc extends Thread{
private int i;
@Override
public void run() {
// TODO Auto-generated method stub
for(i=0;i<10;i++) {
System.out.println(Thread.currentThread().getName()+"i="+i);
}
}
}