|
|
@ -32,6 +32,8 @@ import java.math.BigDecimal; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Timer; |
|
|
|
import java.util.Timer; |
|
|
|
import java.util.TimerTask; |
|
|
|
import java.util.TimerTask; |
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
|
|
|
|
import java.util.concurrent.Executors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by lyy on 2017/1/18. |
|
|
|
* Created by lyy on 2017/1/18. |
|
|
@ -60,6 +62,17 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
private String mTaskType; |
|
|
|
private String mTaskType; |
|
|
|
private Timer mFailTimer; |
|
|
|
private Timer mFailTimer; |
|
|
|
private long mLastSaveTime; |
|
|
|
private long mLastSaveTime; |
|
|
|
|
|
|
|
private ExecutorService mConfigThreadPool; |
|
|
|
|
|
|
|
private Thread mConfigThread = new Thread(new Runnable() { |
|
|
|
|
|
|
|
@Override public void run() { |
|
|
|
|
|
|
|
final long currentTemp = mChildCurrentLocation; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
writeConfig(false, currentTemp); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
protected AbsThreadTask(StateConstance constance, IEventListener listener, |
|
|
|
protected AbsThreadTask(StateConstance constance, IEventListener listener, |
|
|
|
SubThreadConfig<TASK_ENTITY> info) { |
|
|
|
SubThreadConfig<TASK_ENTITY> info) { |
|
|
@ -76,6 +89,7 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed()); |
|
|
|
setMaxSpeed(AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getMsxSpeed()); |
|
|
|
mTaskType = getTaskType(); |
|
|
|
mTaskType = getTaskType(); |
|
|
|
mLastSaveTime = System.currentTimeMillis(); |
|
|
|
mLastSaveTime = System.currentTimeMillis(); |
|
|
|
|
|
|
|
mConfigThreadPool = Executors.newCachedThreadPool(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected abstract String getTaskType(); |
|
|
|
protected abstract String getTaskType(); |
|
|
@ -94,6 +108,13 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; |
|
|
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override protected void finalize() throws Throwable { |
|
|
|
|
|
|
|
super.finalize(); |
|
|
|
|
|
|
|
if (mConfigThreadPool != null) { |
|
|
|
|
|
|
|
mConfigThreadPool.shutdown(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 停止任务 |
|
|
|
* 停止任务 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -134,20 +155,12 @@ public abstract class AbsThreadTask<ENTITY extends AbsNormalEntity, TASK_ENTITY |
|
|
|
synchronized (AriaManager.LOCK) { |
|
|
|
synchronized (AriaManager.LOCK) { |
|
|
|
mChildCurrentLocation += len; |
|
|
|
mChildCurrentLocation += len; |
|
|
|
STATE.CURRENT_LOCATION += len; |
|
|
|
STATE.CURRENT_LOCATION += len; |
|
|
|
//mIncrement += len;
|
|
|
|
|
|
|
|
if (System.currentTimeMillis() - mLastSaveTime > 5000 |
|
|
|
if (System.currentTimeMillis() - mLastSaveTime > 5000 |
|
|
|
&& mChildCurrentLocation < mConfig.END_LOCATION) { |
|
|
|
&& mChildCurrentLocation < mConfig.END_LOCATION) { |
|
|
|
mLastSaveTime = System.currentTimeMillis(); |
|
|
|
mLastSaveTime = System.currentTimeMillis(); |
|
|
|
new Thread(new Runnable() { |
|
|
|
if (!mConfigThreadPool.isShutdown()) { |
|
|
|
@Override public void run() { |
|
|
|
mConfigThreadPool.execute(mConfigThread); |
|
|
|
final long currentTemp = mChildCurrentLocation; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
writeConfig(false, currentTemp); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}).start(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|