使用 join 阻塞
import java.util.concurrent.ExecutionException;
public class ConCurrentTest {
public static void main(String[] args) throws ExecutionException, InterruptedException {
test0();
}
static volatile int result = 0;
private static void test0() {
Thread l = new Thread() {
@Override
public void run() {
try {
Thread.sleep(2_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
result = 66;
}
};
l.start();
try {
l.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(result);
}
}