|
@@ -6,7 +6,6 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fjhx.entity.ConnectConfig;
|
|
|
import com.fjhx.service.Operation;
|
|
|
import com.fjhx.utils.MyUtil;
|
|
|
-import com.fjhx.utils.ThreadPoolManager;
|
|
|
import com.rfid.callBack.CallBack;
|
|
|
import com.rfid.uhf.controller.impl.ReaderR2000;
|
|
|
import com.rfid.uhf.service.ReaderR2000Service;
|
|
@@ -21,35 +20,73 @@ public class TcpOperation implements Operation {
|
|
|
private final ReaderR2000Service service = new ReaderR2000ServiceImpl();
|
|
|
private final List<ReaderR2000> readerR2000List = new ArrayList<>();
|
|
|
private final Set<String> rfidSet = new ConcurrentHashSet<>();
|
|
|
+ private final List<Thread> threadList = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
|
public void distinctRead(String userId, String sessionId, List<ConnectConfig> connectConfigList, JSONObject data) {
|
|
|
|
|
|
for (ConnectConfig connectConfig : connectConfigList) {
|
|
|
- ThreadPoolManager.execute(() -> {
|
|
|
-
|
|
|
- ReaderR2000 reader = service.connect(
|
|
|
- connectConfig.getIp(),
|
|
|
- connectConfig.getPort(),
|
|
|
- getCallBack(userId, sessionId, data)
|
|
|
- );
|
|
|
|
|
|
+ Thread thread = new Thread(() -> {
|
|
|
+ ReaderR2000 reader = service.connect(connectConfig.getIp(), connectConfig.getPort(), getCallBack(userId, sessionId, data));
|
|
|
service.beginInvV2(reader);
|
|
|
readerR2000List.add(reader);
|
|
|
-
|
|
|
});
|
|
|
+ thread.start();
|
|
|
+ threadList.add(thread);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void close() {
|
|
|
+ MyUtil.errorLog("执行close方法,readerR2000List.size() = " + readerR2000List.size());
|
|
|
+
|
|
|
for (ReaderR2000 readerR2000 : readerR2000List) {
|
|
|
- // 结束扫描
|
|
|
- service.stopInvV2(readerR2000);
|
|
|
- // 关闭连接
|
|
|
- service.disconnect(readerR2000);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 结束扫描
|
|
|
+ service.stopInvV2(readerR2000);
|
|
|
+ // 关闭连接
|
|
|
+ service.disconnect(readerR2000);
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // boolean stopInvV2Flag;
|
|
|
+ // boolean disconnectFlag;
|
|
|
+ // do {
|
|
|
+ // try {
|
|
|
+ // // 结束扫描
|
|
|
+ // stopInvV2Flag = service.stopInvV2(readerR2000);
|
|
|
+ // // 关闭连接
|
|
|
+ // disconnectFlag = service.disconnect(readerR2000);
|
|
|
+ // } catch (Exception e) {
|
|
|
+ // MyUtil.errorLog("关闭程序出现异常");
|
|
|
+ //
|
|
|
+ // stopInvV2Flag = false;
|
|
|
+ // disconnectFlag = false;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // if (stopInvV2Flag && disconnectFlag) {
|
|
|
+ // MyUtil.errorLog("关闭程序");
|
|
|
+ // } else {
|
|
|
+ // MyUtil.errorLog("关闭程序失败");
|
|
|
+ // }
|
|
|
+
|
|
|
+ // } while (!stopInvV2Flag || !disconnectFlag);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Thread thread : threadList) {
|
|
|
+ try {
|
|
|
+ thread.stop();
|
|
|
+ } catch (Exception e) {
|
|
|
+ MyUtil.errorLog("关闭线程失败");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private CallBack.R2000 getCallBack(String userId, String sessionId, JSONObject data) {
|