package com.thread.ljb;
public class ThreadTest extends Thread{
public static void main(String[] args) {
MyThread tt = new MyThread();
Thread th = new Thread(tt,"线程1");
th.start();
Thread tt2 = new Thread(tt);
tt2.setName("线程2");
tt2.start();
Thread thread =new Thread(new Runnable() {
@Override
public void run() {
int sum =0;
for(int i =0;i<100;i++) {
sum +=i;
System.out.println(Thread.currentThread().getName()+"--"+sum);
}
}
});
thread.start();
}
}
package com.thread.ljb;
import java.util.Iterator;
public class MyThread implements Runnable{
public void run() {
for(int i =0;i<100;i++) {
System.out.println(Thread.currentThread().getName()+"--"+i);
}
}
}