Example #1
0
 private void dlDispatch() {
   int threadSize;
   int threadLength = LENGTH_PER_THREAD;
   if (info.totalBytes <= LENGTH_PER_THREAD) {
     threadSize = 2;
     threadLength = info.totalBytes / threadSize;
   } else {
     threadSize = info.totalBytes / LENGTH_PER_THREAD;
   }
   int remainder = info.totalBytes % threadLength;
   for (int i = 0; i < threadSize; i++) {
     int start = i * threadLength;
     int end = start + threadLength - 1;
     if (i == threadSize - 1) {
       end = start + threadLength + remainder;
     }
     DLThreadInfo threadInfo =
         new DLThreadInfo(UUID.randomUUID().toString(), info.baseUrl, start, end);
     info.addDLThread(threadInfo);
     // DLDBManager.getInstance(context).insertThreadInfo(threadInfo);
     try {
       mDLThreadInfoDao.save(threadInfo);
     } catch (SQLException e) {
       e.printStackTrace();
     }
     mPreviousTime = System.currentTimeMillis();
     DLManager.getInstance(context).addDLThread(new DLThread(threadInfo, info, this));
   }
 }