标签:let private check ide executors tco int ble cal
java 1.2 前的线程受os内核限制, 线程=进程, 绿色线程是JVM调度, 用来模拟多线程环境. 不需要本地线程支持.
对比
绿色线程在线程激活和线程同步方面优于本地线程
在I/O和上下文操作方面性能要低于本地线程
变通的实现方式:
public static void main(String[] args){
CompletableRunnable runnable = new CompletableRunnable();
Thread thread = new Thread(runnable,"Sub");
thread.start();
thread.join(); //此处阻塞主线程等待Sub完成, 否则得到的结果不准确
System.out.printf("[Thread: %s] is running\n", Thread.currentThread.getName());
System.out.printf("Sub Thread is completed, result is %s\n", runnable.getCompleted());
}
private static class CompletableRunnable implements Runnable{
private volatile boolean completed = false;
@Override
public void run(){
System.out.printf("[Thread: %s] is running\n", Thread.currentThread.getName());
completed = true;
}
public boolean getCompleted(){
return completed;
}
}
ListenableFuture
标签:let private check ide executors tco int ble cal
原文地址:https://www.cnblogs.com/walkinhalo/p/11125719.html