范例:
class MyThread implements Runnable {
private String title;
public MyThread(String title) {
this.title = title;
}
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println(this.title + "->" + i);
}
}
}
public class Demo {
public static void main(String[] args) {
MyThread mt1 = new MyThread("线程1");
MyThread mt2 = new MyThread("线程2");
MyThread mt3 = new MyThread("线程3");
new Thread(mt1).start();
new Thread(mt2).start();
new Thread(mt3).start();
}
}