Java multithreaded asynchronous and blocking invocation methods

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.