2021年1月1日星期五

What happens to main thread when using a callable

When using Callable and Future in Java, what happens to the main thread when the other thread is executing the Callable. Is it sleeping and the other thread wakes it up when it has finished computing the value

import java.util.concurrent.*;  public class AddData {    public static void main(String[] args) throws InterruptedException, ExecutionException {      ExecutorService service = null;      try {          service = Executors.newSingleThreadExecutor();          Future<Integer> result = service.submit(() -> 30+11);          System.out.println(result.get());      } finally {          if(service != null) service.shutdown();      }    }  }  

With multithreading is it possible to see the current status(sleep, doing something) of thread like using VisualVM

https://stackoverflow.com/questions/65535931/what-happens-to-main-thread-when-using-a-callable January 02, 2021 at 12:08PM

没有评论:

发表评论