sdk3.0, using the internal thread pool, multithreading concurrently executes. Thread pool size equals 5, up to 128
After sdk3.0, a thread is executed using the default serial thread pool, and the next thread is executed sequentially. sdk4.3 when the thread pool size equals 5, up to 128
sdk4.4 thread pool size equals CPU Count + 1, max CPU count * 2 + 1
There are two implementations of the thread pool after sdk3.0, and the default is the Serial thread pool
[Java]View Plaincopyprint?
- Public static final Executor serial_executor = new Serialexecutor ();
- Public static final Executor thread_pool_executor
- = New Threadpoolexecutor (Core_pool_size, Maximum_pool_size, Keep_alive,
- Timeunit.seconds, Spoolworkqueue, sthreadfactory);
- Private static volatile Executor sdefaultexecutor = Serial_executor;
- Public static void Setdefaultexecutor (Executor exec) {//Set default thread pool
- Sdefaultexecutor = exec;
- }
Serialexecutor, using a synchronous lock, execute one thread at a time
[Java]View Plaincopyprint?
- Private static class Serialexecutor implements Executor {
- final arraydeque<runnable> mtasks = new arraydeque<runnable> ();
- Runnable mactive;
- public synchronized Void execute (final Runnable R) {
- Mtasks.offer (new Runnable () {
- public Void Run () {
- try {
- R.run ();
- } finally {
- Schedulenext ();
- }
- }
- });
- if (mactive = = null) {
- Schedulenext ();
- }
- }
- protected synchronized void Schedulenext () {
- if ((mactive = Mtasks.poll ()) = null) {
- Thread_pool_executor.execute (mactive);
- }
- }
- }
sdk3.0, using the internal thread pool, multithreading concurrently executes. Thread pool size equals 5, up to 128
After sdk3.0, a thread is executed using the default serial thread pool, and the next thread is executed sequentially. sdk4.3 when the thread pool size equals 5, up to 128
sdk4.4 thread pool size equals CPU Count + 1, max CPU count * 2 + 1
There are two implementations of the thread pool after sdk3.0, and the default is the Serial thread pool
[Java]View Plaincopyprint?
- Public static final Executor serial_executor = new Serialexecutor ();
- Public static final Executor thread_pool_executor
- = New Threadpoolexecutor (Core_pool_size, Maximum_pool_size, Keep_alive,
- Timeunit.seconds, Spoolworkqueue, sthreadfactory);
- Private static volatile Executor sdefaultexecutor = Serial_executor;
- Public static void Setdefaultexecutor (Executor exec) {//Set default thread pool
- Sdefaultexecutor = exec;
- }
Serialexecutor, using a synchronous lock, execute one thread at a time[Java]View Plaincopyprint?
- Private static class Serialexecutor implements Executor {
- final arraydeque<runnable> mtasks = new arraydeque<runnable> ();
- Runnable mactive;
- public synchronized Void execute (final Runnable R) {
- Mtasks.offer (new Runnable () {
- public Void Run () {
- try {
- R.run ();
- } finally {
- Schedulenext ();
- }
- }
- });
- if (mactive = = null) {
- Schedulenext ();
- }
- }
- protected synchronized void Schedulenext () {
- if ((mactive = Mtasks.poll ()) = null) {
- Thread_pool_executor.execute (mactive);
- }
- }
Thread_pool_executor Concurrent Thread pool
Asynctask.setdefaultexecutor (Asynctask.thread_pool_executor); Set up to use the concurrency thread pool
Asynctask.executeonexecutor (executor); You can customize the thread pool using both of these methods
Thread_pool_executor Concurrent Thread pool
Asynctask.setdefaultexecutor (Asynctask.thread_pool_executor); Set up to use the concurrency thread pool
Asynctask.executeonexecutor (executor); You can customize the thread pool using both of these methods