|
|
@ -28,6 +28,8 @@ import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
import java.util.Timer; |
|
|
|
|
|
|
|
import java.util.TimerTask; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Created by lyy on 2017/1/18. |
|
|
|
* Created by lyy on 2017/1/18. |
|
|
@ -35,6 +37,14 @@ import java.util.Properties; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> |
|
|
|
public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity<ENTITY>> |
|
|
|
implements Runnable { |
|
|
|
implements Runnable { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 线程重试次数 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private final int RETRY_NUM = 5; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 线程重试间隔 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private final int RETRY_INTERVAL = 5000; |
|
|
|
private final String TAG = "AbsThreadTask"; |
|
|
|
private final String TAG = "AbsThreadTask"; |
|
|
|
protected long mChildCurrentLocation = 0, mSleepTime = 0; |
|
|
|
protected long mChildCurrentLocation = 0, mSleepTime = 0; |
|
|
|
protected int mBufSize; |
|
|
|
protected int mBufSize; |
|
|
@ -48,6 +58,8 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend |
|
|
|
* FTP 服务器编码 |
|
|
|
* FTP 服务器编码 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static String SERVER_CHARSET = "ISO-8859-1"; |
|
|
|
public static String SERVER_CHARSET = "ISO-8859-1"; |
|
|
|
|
|
|
|
private int mFailNum = 0; |
|
|
|
|
|
|
|
private Timer mFailTimer; |
|
|
|
|
|
|
|
|
|
|
|
protected AbsThreadTask(StateConstance constance, IEventListener listener, |
|
|
|
protected AbsThreadTask(StateConstance constance, IEventListener listener, |
|
|
|
SubThreadConfig<TASK_ENTITY> info) { |
|
|
|
SubThreadConfig<TASK_ENTITY> info) { |
|
|
@ -168,11 +180,11 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend |
|
|
|
writeConfig(false, currentLocation); |
|
|
|
writeConfig(false, currentLocation); |
|
|
|
if (STATE.isFail()) { |
|
|
|
if (STATE.isFail()) { |
|
|
|
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败"); |
|
|
|
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败"); |
|
|
|
mListener.onFail(); |
|
|
|
mListener.onFail(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败"); |
|
|
|
Log.e(TAG, "任务【" + mConfig.TEMP_FILE.getName() + "】执行失败"); |
|
|
|
mListener.onFail(); |
|
|
|
mListener.onFail(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
@ -180,6 +192,24 @@ public abstract class AbsThreadTask<ENTITY extends AbsEntity, TASK_ENTITY extend |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 重试当前线程 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void retryThis(boolean needRetry) { |
|
|
|
|
|
|
|
if (mFailNum < RETRY_NUM && needRetry) { |
|
|
|
|
|
|
|
if (mFailTimer != null){ |
|
|
|
|
|
|
|
mFailTimer.purge(); |
|
|
|
|
|
|
|
mFailTimer.cancel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mFailTimer = new Timer(); |
|
|
|
|
|
|
|
mFailTimer.schedule(new TimerTask() { |
|
|
|
|
|
|
|
@Override public void run() { |
|
|
|
|
|
|
|
AbsThreadTask.this.run(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, RETRY_INTERVAL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 将记录写入到配置文件 |
|
|
|
* 将记录写入到配置文件 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|