Java multithreading can be directly through the Executorservice interface of the Execute method to submit tasks, or through the InvokeAll method to allow multiple tasks together, the former execute is asynchronous commit, that is, will not block the main thread, will block the main thread, Wait for all tasks to complete the main line Cheng back to execution. In fact, whether execute or InvokeAll, they will eventually go to execute the executor interface of the Execute (Runnable run) method, the following is intercepted part of the source code
It is obvious that the InvokeAll method invoked execute and passed in a Runnablefuture object that inherits from the Runnable interface, so the principle is the same, and it is also noted that the future object's get is also called. This method is blocking, which is why InvokeAll blocks the main thread.