Java Multithreading (10) Control task Group __java

Source: Internet
Author: User
Overview

As a thread pool, the executor service can not only improve the efficiency of performing tasks, but also control a set of related tasks. For example, you can use the Shutdownnow method in the executor to cancel all tasks. Control Task Group

java.util.concurrent.executorservice T invokeany (collection<callable<t>> Tasks) T Invokeany (collection<callable<t>> tasks, long timeout,timeunit unit)//Perform a given task,
Returns the result of one of the tasks (any completed results of the program). The second method, if a timeout occurs, throws a TimeoutException exception list<future<t>> InvokeAll (collection<callable<t>> Tasks) list<future<t>> InvokeAll (collection<callable<t>> tasks,long timeout, TimeUnit unit) /perform the given task and return all the results.

The second method throws a timeout exception exception if a timeout occurs java.util.concurrent.executorcompletionservice<v> Executorcompletionservice (Executor E)//build an executor to complete the service to collect the results of a given executor future<v> submit (callable<v> Task) Future <V> Submit (Runnable task,v Results)//Submit a task to the underlying executor future<v> take ()//Remove the next completed result, blocking Future if no completed results are available <V> poll () future<v> poll (long time,timeunit unit)//Remove the next completed result and return NULL if no completed results are available. The second method waits for a given time. 

PS: Where InvokeAll has a special place: if it creates 3 tasks, he will create a new 2 child threads, and the remaining tasks will continue to execute on this 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.