Browse Source

REPORT-83195 卡顿点优化-根据插件提示修改了一下代码规范

feature/x
John.Ying-应志浩 2 years ago
parent
commit
c600233de6
  1. 37
      designer-base/src/main/java/com/fr/design/carton/developer/EventDispatchDeveloperMode.java
  2. 37
      designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java
  3. 10
      designer-base/src/main/java/com/fr/design/worker/save/type/SaveTypeWorker.java

37
designer-base/src/main/java/com/fr/design/carton/developer/EventDispatchDeveloperMode.java

@ -1,6 +1,7 @@
package com.fr.design.carton.developer;
import com.aspose.words.Run;
import com.fr.concurrent.FineExecutors;
import com.fr.design.carton.EventDispatchThreadHangMonitor;
import com.fr.design.ui.util.UIUtil;
@ -33,7 +34,9 @@ public final class EventDispatchDeveloperMode extends EventQueue {
*/
public static final long CHECK_INTERVAL_MS = 5;
private Timer timer;
private static final int CORE_THREAD_SIZE = 5;
private ScheduledExecutorService timer;
/**
* edt事件最大允许的时间
@ -76,6 +79,7 @@ public final class EventDispatchDeveloperMode extends EventQueue {
long nowTime = System.currentTimeMillis();
long totalTime = nowTime - awtEventInfo.getStartDispatchTimeMillis();
long continuationTime = nowTime - awtEventInfo.getLastDispatchTimeMillis();
//判断连续执行时间是否超过了20ms,超过了则进行提示
if (continuationTime > MAX_TIME) {
FineLoggerFactory.getLogger()
.warn("awt event spend time more than 20ms, totalTime {} continuationTime {} the stack is {}"
@ -99,26 +103,8 @@ public final class EventDispatchDeveloperMode extends EventQueue {
*/
public void initTimer() {
final long initialDelayMs = 0;
final boolean daemon = true;
timer = new Timer("EventDispatchDeveloperMode", daemon);
timer.schedule(new HangChecker(), initialDelayMs, CHECK_INTERVAL_MS);
}
/**
* /消除Timer
*/
public void stopTimer() {
if (timer != null) {
timer.cancel();
}
}
/**
* /定时执行的任务
*/
public class HangChecker extends TimerTask {
@Override
public void run() {
timer = FineExecutors.newScheduledThreadPool(CORE_THREAD_SIZE);
timer.schedule(() -> {
synchronized (dispatches) {
//如果链表为空定时检测就不进行
if (dispatches.isEmpty()) {
@ -126,6 +112,15 @@ public final class EventDispatchDeveloperMode extends EventQueue {
}
dispatches.getLast().checkForHang();
}
}, initialDelayMs, TimeUnit.MILLISECONDS);
}
/**
* /消除Timer
*/
public void stopTimer() {
if (timer != null) {
timer.shutdown();
}
}

37
designer-base/src/main/java/com/fr/design/worker/save/SaveWorker.java

@ -7,6 +7,7 @@ import com.fr.design.mainframe.EastRegionContainerPane;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.ui.util.UIUtil;
import com.fr.design.worker.WorkerManager;
import com.fr.design.worker.save.type.SaveTypeWorker;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
@ -87,26 +88,24 @@ public class SaveWorker extends SwingWorker<Boolean, Void> {
this.execute();
// worker纳入管理
WorkerManager.getInstance().registerWorker(taskName, this);
if (!slowly) {
new Thread(() -> {
while (true) {
if (stopWatch.getTime() > TIME_OUT || isDone()) {
if (!isDone()) {
slowly = true;
UIUtil.invokeLaterIfNeeded(() -> {
// 开始禁用
if (slowly) {
EastRegionContainerPane.getInstance().updateAllPropertyPane();
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover();
DesignerFrameFileDealerPane.getInstance().stateChange();
}
});
}
stopWatch.stop();
break;
SaveTypeWorker.saveTypePool.execute(() -> {
while (true) {
if (stopWatch.getTime() > TIME_OUT || isDone()) {
if (!isDone()) {
slowly = true;
UIUtil.invokeLaterIfNeeded(() -> {
// 开始禁用
if (slowly) {
EastRegionContainerPane.getInstance().updateAllPropertyPane();
DesignerContext.getDesignerFrame().getCenterTemplateCardPane().showCover();
DesignerFrameFileDealerPane.getInstance().stateChange();
}
});
}
stopWatch.stop();
break;
}
}).start();
}
}
});
}
}

10
designer-base/src/main/java/com/fr/design/worker/save/type/SaveTypeWorker.java

@ -1,6 +1,7 @@
package com.fr.design.worker.save.type;
import com.fr.concurrent.FineExecutors;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrameFileDealerPane;
import com.fr.design.mainframe.EastRegionContainerPane;
@ -10,6 +11,7 @@ import com.fr.third.org.apache.commons.lang3.time.StopWatch;
import javax.swing.SwingWorker;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
/**
* 判断保存类别时执行的worker
@ -20,6 +22,8 @@ import java.util.concurrent.Callable;
*/
public class SaveTypeWorker extends SwingWorker<SaveType, Void> {
public static final ExecutorService saveTypePool = FineExecutors.newSingleThreadExecutor();
private final Callable<SaveType.TypeEnum> callable;
private static final int TIME_OUT = 400;
@ -28,6 +32,8 @@ public class SaveTypeWorker extends SwingWorker<SaveType, Void> {
private final SaveType saveType;
public SaveTypeWorker(Callable<SaveType.TypeEnum> callable, JTemplate<?, ?> template) {
this.callable = callable;
this.template = template;
@ -52,7 +58,7 @@ public class SaveTypeWorker extends SwingWorker<SaveType, Void> {
StopWatch stopWatch = StopWatch.createStarted();
this.template.setSaving(true);
this.execute();
new Thread(() -> {
saveTypePool.execute(() -> {
while (true) {
//大于最大等待时间或者worker已经完成该线程都要结束循环
if (stopWatch.getTime() > TIME_OUT || isDone()) {
@ -70,6 +76,6 @@ public class SaveTypeWorker extends SwingWorker<SaveType, Void> {
break;
}
}
}).start();
});
}
}

Loading…
Cancel
Save