标签:android asynctask 线程 源码 线程池
转载请注明出处:http://blog.csdn.net/itachi85/article/details/45055365private 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); } }
private static final int CORE_POOL_SIZE = 5; private static final int MAXIMUM_POOL_SIZE = 128; private static final int KEEP_ALIVE = 1; ... public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory);
AsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
LikeListTask mLikeListTask=new LikeListTask(); mLikeListTask.executeOnExecutor(Executors.newCachedThreadPool(), null);
Executor exec =new ThreadPoolExecutor(0, Integer.MAX_VALUE, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); new LikeListTask().executeOnExecutor(exec, null);
标签:android asynctask 线程 源码 线程池
原文地址:http://blog.csdn.net/itachi85/article/details/45055365