package com.jbx.thread;
/**
* 3个线程,A,B,C,这三个线程分别只能打印 “a”,“b”,“c”,怎么让这三个线程依次打印“abc"
*
* @author Administrator
*
*/
public class TestJoin {
public static void main(String[] args) {
Thread a = new Thread(new AThread());
Thread b = new Thread(new BThread());
Thread c = new Thread(new CThread());
a.start();
try {
a.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
b.start();
try {
b.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
c.start();
try {
c.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class AThread implements Runnable {
@Override
public void run() {
System.out.println("a");
}
}
class BThread implements Runnable {
@Override
public void run() {
System.out.println("b");
}
}
class CThread implements Runnable {
@Override
public void run() {
System.out.println("c");
}
}
执行结果:
a
b
c
这种方式经测试在main方法中加入循环方法之后无法实现依次输出abcabcabc