fix bug of AISDK about socket

This commit is contained in:
zhongchao
2021-03-10 12:13:44 +08:00
parent 5a2f7e3af9
commit 75d877fedf
6 changed files with 29 additions and 87 deletions

View File

@@ -1,10 +1,11 @@
package com.mogo.realtime.core;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.support.annotation.Keep;
import com.mogo.cloud.WorkThreadHandler;
import com.mogo.cloud.utils.logger.Logger;
import static com.mogo.realtime.constant.RealTimeConstant.TAG;
@@ -17,7 +18,8 @@ public class UploadInTimeHandler {
private static final long MSG_DATA_INTERNAL = 500L;
private final long uploadDelay = MSG_DATA_INTERNAL;
private Handler mHandler;
private volatile HandlerThread mThread;
private volatile Handler mHandler;
private static volatile UploadInTimeHandler uploadInTimeHandler;
private IUploadInTimeListener iUploadInTimeListener;
@@ -37,9 +39,15 @@ public class UploadInTimeHandler {
return uploadInTimeHandler;
}
public void start() {
public synchronized void start() {
Logger.d(TAG, "UploadInTimeHandler start");
if (mHandler == null) {
mHandler = new Handler(WorkThreadHandler.newInstance(TAG).getLooper()) {
if (mThread == null) {
mThread = new HandlerThread(TAG);
Logger.d(TAG, "start Handler Thread");
mThread.start();
}
mHandler = new Handler(mThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
@@ -71,11 +79,20 @@ public class UploadInTimeHandler {
}
}
public void stop() {
if (mHandler != null && mHandler.hasMessages(MSG_DATA_CHANGED)) {
public synchronized void stop() {
if (mHandler != null) {
mHandler.removeMessages(MSG_DATA_CHANGED);
mHandler = null;
}
if (mThread != null) {
try {
mThread.quit();
} catch (Exception e) {
e.printStackTrace();
}
mThread = null;
Logger.d(TAG, "stop Thread set null");
}
iUploadInTimeListener = null;
uploadInTimeHandler = null;
}