我是MultiThreading的新手。我正在尝试下面提到的例子:
class Multi implements Runnable {
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(500);
System.out.println(Thread.currentThread().getName()
+ " is running..."+i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String args[]) {
Multi m1 = new Multi();
Multi m2 = new Multi();
Thread t1 = new Thread(m1, "t1");
Thread t2 = new Thread(m2, "t2");
t1.start();
t2.start();
}
}
如果我从同一个Multi Class对象创建两个线程,虽然输出相同,但它会创建什么区别?
Multi m1 = new Multi();
Thread t1 = new Thread(m1, "t1");
Thread t2 = new Thread(m1, "t2");