AsyncTask在Android4.X的机制问题
在遵义等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站设计 网站设计制作按需策划设计,公司网站建设,企业网站建设,成都品牌网站建设,营销型网站建设,外贸网站制作,遵义网站建设费用合理。
AsyncTask在Android4.X机制是串行的...单一AsyncTask运行完才会运行下一个
AsyncTask在Android2.3机制是并行的..最多支持5个
解决AsyncTask 在4.x串行的问题...自己编写线程池
public class PoolThread {
private static final int CPU_COUNT = Runtime.getRuntime()
.availableProcessors();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 10 + 1;
private static final int KEEP_ALIVE = 1;
private static final BlockingQueue
128);
private static final ThreadFactory sThreadFactory = new ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);
public Thread newThread(Runnable r) {
return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
}
};
public static final Executor THREAD_POOL_EXECUTOR = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE, TimeUnit.SECONDS,
sPoolWorkQueue, sThreadFactory);
}
启动 AsyncTask 的时候 reTask.executeOnExecutor(PoolThread.THREAD_POOL_EXECUTOR,params...)
就可以并行咯..