Tasks in the Android thread pool are canceled

Source: Internet
Author: User

============ Problem Description ============


Executorservice pool = Executors.newfixedthreadpool (2);
The Runnable interface object is created, and the thread object, of course, implements the Runnable interface.
Thread T1 = new MyThread ();
Thread t2 = new MyThread ();
Thread t3 = new MyThread ();
Thread T4 = new MyThread ();
Thread T5 = new MyThread ();
Putting a thread into the pool for execution
Pool.execute (t1);
Pool.execute (T2);
Pool.execute (T3);
Pool.execute (T4);
Pool.execute (T5);


The above creates a thread pool that is fixed to 2 threads, and at some point there is no way to judge whether T1, T2, T3, T4, T5 are waiting in line, or are already executing, because I want to cancel the task that is waiting in line, lest waste resources
Note: I use the first method in this article http://blog.csdn.net/lyf_007217/article/details/8542238

============ Solution 1============


Java.util.concurrent.ExecutorService;
Java.util.concurrent.Executors;
Look at the APIs inside these two packages.

============ Solution 2============


Intentservice provides a worker thread queue.

============ Solution 3============


To cancel, implement the callable interface, then call the Pool.submit () method, return the Futrue object, and use the future object to get the state of the thread.

These are the things inside J U C.
SOURCE analysis See:
http://blog.csdn.net/windsunmoon/article/details/36903901

Tasks in the Android thread pool are canceled

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.