Skip to content

Commit 2df6766

Browse files
committed
code optimization
1 parent 104f21b commit 2df6766

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

‎src/main/java/com/fangxuele/tool/push/logic/msgthread/BaseMsgThread.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ public class BaseMsgThread extends Thread {
5050
/**
5151
* 当前线程成功数
5252
*/
53-
public final ThreadLocal<Integer> currentThreadSuccessCount = ThreadLocal.withInitial(() -> 0);
53+
public final ThreadLocal<Integer> successCountLocal = ThreadLocal.withInitial(() -> 0);
5454

5555
/**
5656
* 当前线程失败数
5757
*/
58-
public final ThreadLocal<Integer> currentThreadFailCount = ThreadLocal.withInitial(() -> 0);
58+
public final ThreadLocal<Integer> failCountLocal = ThreadLocal.withInitial(() -> 0);
5959

6060
/**
6161
* 线程列表table
6262
*/
63-
public JTable pushThreadTable;
63+
public final ThreadLocal<JTable> pushTableLocal = new ThreadLocal<>();
6464

6565
/**
6666
* 当前线程所在的线程列表行
@@ -95,13 +95,13 @@ public void initCurrentThread() {
9595
list = PushData.toSendList.subList(startIndex, endIndex);
9696

9797
// 初始化线程列表行
98-
pushThreadTable = PushForm.getInstance().getPushThreadTable();
99-
currentThreadSuccessCount.set(0);
100-
currentThreadFailCount.set(0);
101-
pushThreadTable.setValueAt(currentThreadSuccessCount.get(), tableRow, 2);
102-
pushThreadTable.setValueAt(currentThreadFailCount.get(), tableRow, 3);
103-
pushThreadTable.setValueAt(list.size(), tableRow, 4);
104-
pushThreadTable.setValueAt(0, tableRow, 5);
98+
pushTableLocal.set(PushForm.getInstance().getPushThreadTable());
99+
successCountLocal.set(0);
100+
failCountLocal.set(0);
101+
pushTableLocal.get().setValueAt(successCountLocal.get(), tableRow, 2);
102+
pushTableLocal.get().setValueAt(failCountLocal.get(), tableRow, 3);
103+
pushTableLocal.get().setValueAt(list.size(), tableRow, 4);
104+
pushTableLocal.get().setValueAt(0, tableRow, 5);
105105
}
106106

107107
/**

‎src/main/java/com/fangxuele/tool/push/logic/msgthread/MsgSendThread.java‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public void run() {
6262
PushForm.getInstance().getPushSuccessCount().setText(String.valueOf(PushData.successRecords));
6363

6464
// 当前线程发送成功+1
65-
currentThreadSuccessCount.set(currentThreadSuccessCount.get() + 1);
66-
pushThreadTable.setValueAt(currentThreadSuccessCount.get(), tableRow, 2);
65+
successCountLocal.set(successCountLocal.get() + 1);
66+
pushTableLocal.get().setValueAt(successCountLocal.get(), tableRow, 2);
6767

6868
// 保存发送成功
6969
PushData.sendSuccessList.add(msgData);
@@ -79,12 +79,12 @@ public void run() {
7979
ConsoleUtil.consoleOnly("发送失败:" + sendResult.getInfo() + ";msgData:" + JSONUtil.toJsonPrettyStr(msgData));
8080

8181
// 当前线程发送失败+1
82-
currentThreadFailCount.set(currentThreadFailCount.get() + 1);
83-
pushThreadTable.setValueAt(currentThreadFailCount.get(), tableRow, 3);
82+
failCountLocal.set(failCountLocal.get() + 1);
83+
pushTableLocal.get().setValueAt(failCountLocal.get(), tableRow, 3);
8484
}
8585

8686
// 当前线程进度条
87-
pushThreadTable.setValueAt((int) ((double) (i + 1) / list.size() * 100), tableRow, 5);
87+
pushTableLocal.get().setValueAt((int) ((double) (i + 1) / list.size() * 100), tableRow, 5);
8888

8989
// 总进度条
9090
PushForm.getInstance().getPushTotalProgressBar().setValue(PushData.successRecords.intValue() + PushData.failRecords.intValue());
@@ -95,8 +95,9 @@ public void run() {
9595
} catch (Exception e) {
9696
logger.error(ExceptionUtils.getStackTrace(e));
9797
} finally {
98-
currentThreadSuccessCount.remove();
99-
currentThreadFailCount.remove();
98+
successCountLocal.remove();
99+
failCountLocal.remove();
100+
pushTableLocal.remove();
100101
}
101102

102103
}

0 commit comments

Comments
 (0)