package chapter1;
public class MyRunnable implements Runnable{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
Thread thread = Thread.currentThread();
System.out.println(thread.getName()+": "+i);
}
}
}
package chapter1;
public class Demo {
public static void main(String[] args) {
MyRunnable myRunnable = new MyRunnable();
// myRunnable.run();
// Thread thread = Thread.currentThread();
// System.out.println(thread);
Thread t1 = new Thread(myRunnable,"线程1");
Thread t2 = new Thread(myRunnable,"线程2");
t1.start();
t2.start();
}
}