Java中的多线程
实现类:
public class hello implements Runnable {
private String name;
hello(){ };
hello(String name){
this.name = name;
}
public void run() {
for (int i = 0; i < 10000; i++) {
System.out.println(name+" Run "+i);
}
}
使用:
public static void main(String[] args) {
hello h1 = new hello("多线程A");
Thread t1 = new Thread(h1);
hello h2 = new hello("多线程B");
Thread t2 = new Thread(h2);
t1.start();
t2.start();
}
结果:
可以看出 A,B是同时进行的。