class SecondThread implements Runnable {
int i;
public void run() {
for(int i=1;i<51;i++) {
System.out.println(Thread.currentThread().getName()+" "+i);
}
}
}
public class TestThread2 {
public static void main(String[] args) {
SecondThread s = new SecondThread();
Thread t = new Thread(s,"子线程1");
Thread k = new Thread(s,"子线程2");
t.start();
k.start();
}
}
两个线程都输出这个么?
public class ThredPrint {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PrintT pt = new PrintT();
Thread ta = new Thread(pt);
Thread tb = new Thread(pt);
ta.start();
tb.start();
}
}
class PrintT implements Runnable {
public void run() {
for(int i = 1; i <= 50; i++) {
System.out.println(i);
try {
Thread.sleep(10);
} catch(Exception e) {
e.printStackTrace();
}
}
}
}