コード例 #1
0
 protected static synchronized void scheduleNext() {
   // 取得头队列并执行
   if ((mActive = mTasks.poll()) != null) {
     threadPoolExecutor.execute(mActive);
   }
   Runnable runnable = mTasks.poll();
   if (runnable != null) {
     threadPoolExecutor.execute(mActive);
   }
   Runnable runnable1 = mTasks.poll();
   if (runnable1 != null) {
     threadPoolExecutor.execute(mActive);
   }
   Runnable runnable2 = mTasks.poll();
   if (runnable2 != null) {
     threadPoolExecutor.execute(mActive);
   }
 }
コード例 #2
0
 public Thread newThread(Runnable r) {
   //        	int requestToken = -1;
   //        	if (r instanceof WeDroidBusiness){
   //        		WeDroidBusiness baseServiceImpl = (WeDroidBusiness) r;
   //        		requestToken = baseServiceImpl.getRequestToken();
   //        	}
   if (mTasks != null) WedroidLog.e("CurrentThread", "请求队列中有" + mTasks.size() + "个任务待执行");
   Thread t = new Thread(r);
   t.setName("SidiHttpExecutor#Thread#" + mCount.getAndIncrement());
   return t;
 }
コード例 #3
0
 /**
  * @param runnable
  * @param priority: THREAD_DEFAULT_PRIOITY or THREAD_HIGH_PRIOITY
  */
 public static void execute(final Runnable runnable, int priority) {
   Runnable r =
       new Runnable() {
         public void run() {
           try {
             runnable.run();
           } finally {
             scheduleNext();
           }
         }
       };
   if (priority == THREAD_HIGH_PRIOITY) {
     // 在队列的最前面入队
     mTasks.offerFirst(r);
   } else {
     mTasks.offer(r);
   }
   //        if (mActive == null) {
   scheduleNext();
   //        }
 }
コード例 #4
0
 /**
  * @Title: tasksClear @Description: 清除所有的待执行任务
  *
  * @author 吴传龙
  */
 public static synchronized void tasksClear() {
   if (mTasks != null) {
     mTasks.clear();
   }
 }