onecoders / Knowledge

Accumulation
0 stars 2 forks source link

Blocking caused by Multi Thread in AsyncTask #54

Open onecoders opened 10 years ago

onecoders commented 10 years ago

http://rincliu.com/blog/2013/07/26/asynctaskde-zu-sai-wen-ti

onecoders commented 10 years ago

@TargetApi(Build.VERSION_CODES.HONEYCOMB) void startMyTask(AsyncTask asyncTask) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); }else{ asyncTask.execute(params); } }

onecoders commented 10 years ago

int corePoolSize = 60; int maximumPoolSize = 80; int keepAliveTime = 10; BlockingQueue workQueue = new LinkedBlockingQueue(maximumPoolSize); Executor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.SECONDS, workQueue); asyncTask.executeOnExecutor(threadPoolExecutor);

onecoders commented 10 years ago

http://rincliu.com/blog/2013/07/26/asynctaskde-zu-sai-wen-ti