package HeadFirstJava;
public class RunThreads implements Runnable {
public static void main(String[] args) {
RunThreads runner = new RunThreads(); // make a Runnable object
Thread alpha = new Thread(runner);
Thread beta = new Thread(runner);
alpha.setName("Alpha thread");
beta.setName("Beta thread");
alpha.start();
beta.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 1000; i++) {
String threadName = Thread.currentThread().getName();
System.out.println(threadName + " is running");
}
}
}
start 2 threads
最新推荐文章于 2022-12-06 15:09:23 发布