Browse Source

REPORT-72634 设计器卡顿优化一期

feature/x
John.Ying 2 years ago
parent
commit
a201f380db
  1. 18
      designer-base/src/main/java/com/fr/design/carton/CartonThreadExecutorPool.java
  2. 1
      designer-base/src/main/java/com/fr/design/carton/CartonUploadMessage.java
  3. 74
      designer-base/src/main/java/com/fr/design/carton/EventDispatchThreadHangMonitor.java
  4. 5
      designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java
  5. 20
      designer-base/src/main/java/com/fr/design/carton/SwitchForSwingChecker.java
  6. 1
      designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java
  7. 2
      designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorAction.java

18
designer-base/src/main/java/com/fr/design/carton/CartonThreadExecutorPool.java

@ -12,12 +12,16 @@ import java.util.concurrent.atomic.AtomicLong;
public class CartonThreadExecutorPool extends ThreadPoolExecutor { public class CartonThreadExecutorPool extends ThreadPoolExecutor {
//一个标识位用于区分耗时任务时长检测(简单检测)和timer检测 /**
* 一个标识位用于区分耗时任务时长检测(简单检测)和timer检测
*/
private static final int TIMER_CHECK_FLAG = 0; private static final int TIMER_CHECK_FLAG = 0;
private static final int EASY_CHECK_FLAG = 1; private static final int EASY_CHECK_FLAG = 1;
private static final int MAX_LIVE_TIME = 3000; private static final int MAX_LIVE_TIME = 3000;
private static final int MAX_WORKER_THREADS = 10; private static final int MAX_WORKER_THREADS = 10;
// 开启间隔检测后两次检测的相隔时间ms /**
* 开启间隔检测后两次检测的相隔时间ms
*/
private static final long CHECK_INTERVAL_MS = 100; private static final long CHECK_INTERVAL_MS = 100;
private final ThreadLocal<StackTraceElement[]> startReportedStack = new ThreadLocal<>(); private final ThreadLocal<StackTraceElement[]> startReportedStack = new ThreadLocal<>();
private volatile static CartonThreadExecutorPool cartonThreadExecutorPool; private volatile static CartonThreadExecutorPool cartonThreadExecutorPool;
@ -25,7 +29,9 @@ public class CartonThreadExecutorPool extends ThreadPoolExecutor {
private static final SimpleDateFormatThreadSafe simpleDateFormatThreadSafe = new SimpleDateFormatThreadSafe(); private static final SimpleDateFormatThreadSafe simpleDateFormatThreadSafe = new SimpleDateFormatThreadSafe();
private final static AtomicLong hangCount = new AtomicLong(0); private final static AtomicLong hangCount = new AtomicLong(0);
private Timer timer; private Timer timer;
//一个变量,用于控制easy监测模式的开关 /**
* 一个变量用于控制easy监测模式的开关
*/
private boolean easyWitch = false; private boolean easyWitch = false;
public boolean isEasyWitch() { public boolean isEasyWitch() {
@ -70,11 +76,15 @@ public class CartonThreadExecutorPool extends ThreadPoolExecutor {
EventDispatchThreadHangMonitor.checkForDeadlock(); EventDispatchThreadHangMonitor.checkForDeadlock();
} }
} }
//来自SwingWorker类
/**
* 来自SwingWorker类
*/
public static ThreadFactory threadFactory = public static ThreadFactory threadFactory =
new ThreadFactory() { new ThreadFactory() {
final ThreadFactory defaultFactory = final ThreadFactory defaultFactory =
Executors.defaultThreadFactory(); Executors.defaultThreadFactory();
@Override
public Thread newThread(final Runnable r) { public Thread newThread(final Runnable r) {
Thread thread = Thread thread =
defaultFactory.newThread(r); defaultFactory.newThread(r);

1
designer-base/src/main/java/com/fr/design/carton/CartonUploadMessage.java

@ -1,6 +1,5 @@
package com.fr.design.carton; package com.fr.design.carton;
import org.nfunk.jep.function.Str;
public class CartonUploadMessage { public class CartonUploadMessage {
private String hangCount; private String hangCount;

74
designer-base/src/main/java/com/fr/design/carton/EventDispatchThreadHangMonitor.java

@ -30,32 +30,52 @@ import java.util.TimerTask;
*/ */
public final class EventDispatchThreadHangMonitor extends EventQueue { public final class EventDispatchThreadHangMonitor extends EventQueue {
//一个标识位用于区分耗时任务时长检测(简单检测)和timer检测 /**
* 一个标识位用于区分耗时任务时长检测(简单检测)和timer检测
*/
private static final int TIMER_CHECK_FLAG = 0; private static final int TIMER_CHECK_FLAG = 0;
private static final int EASY_CHECK_FLAG = 1; private static final int EASY_CHECK_FLAG = 1;
//日期事件格式 /**
* 日期事件格式
*/
private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static final EventDispatchThreadHangMonitor INSTANCE = new EventDispatchThreadHangMonitor(); public static final EventDispatchThreadHangMonitor INSTANCE = new EventDispatchThreadHangMonitor();
//一个timer /**
* 一个timer
*/
private Timer timer; private Timer timer;
// 开启间隔检测后两次检测的相隔时间ms /**
* 开启间隔检测后两次检测的相隔时间ms
*/
private static final long CHECK_INTERVAL_MS = 100; private static final long CHECK_INTERVAL_MS = 100;
// 最大的事件允许执行时间,超过该时间则打印堆栈等相关信息 /**
* 最大的事件允许执行时间超过该时间则打印堆栈等相关信息
*/
private static final long UNREASONABLE_DISPATCH_DURATION_MS = 2000; private static final long UNREASONABLE_DISPATCH_DURATION_MS = 2000;
//事件唯一编码,用于方便日志的查看 /**
* /事件唯一编码用于方便日志的查看
*/
private static long hangCount = 0; private static long hangCount = 0;
//输出日志所在地址 /**
* /输出日志所在地址
*/
private static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log"); private static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log");
//类似于一个开关,当该值为默认的false启动时,定时任务在窗口开启前都不会对执行的事件进行检查 /**
* /类似于一个开关当该值为默认的false启动时定时任务在窗口开启前都不会对执行的事件进行检查
*/
private boolean haveShownSomeComponent = false; private boolean haveShownSomeComponent = false;
//该链表为主要的实现定时任务的容器,在重写的dispatchEvent中由pre方法将DispatchInfo加入到链表,由post方法remove /**
* /该链表为主要的实现定时任务的容器在重写的dispatchEvent中由pre方法将DispatchInfo加入到链表由post方法remove
*/
private final LinkedList<DispatchInfo> dispatches = new LinkedList<DispatchInfo>(); private final LinkedList<DispatchInfo> dispatches = new LinkedList<DispatchInfo>();
//一个变量,用于控制easy监测模式的开关 /**
* /一个变量用于控制easy监测模式的开关
*/
private boolean easyWitch = false; private boolean easyWitch = false;
public boolean isEasyWitch() { public boolean isEasyWitch() {
@ -65,7 +85,11 @@ public final class EventDispatchThreadHangMonitor extends EventQueue {
public void setEasyWitch(boolean easyWitch) { public void setEasyWitch(boolean easyWitch) {
this.easyWitch = easyWitch; this.easyWitch = easyWitch;
} }
//一个变量,用于记录Timer的开关。
/**
* /一个变量用于记录Timer的开关
*
*/
public boolean isTimerWitch() { public boolean isTimerWitch() {
return timerWitch; return timerWitch;
@ -92,15 +116,24 @@ public final class EventDispatchThreadHangMonitor extends EventQueue {
} }
return true; return true;
} }
// 用于堆栈的比较
/**
* / 用于堆栈的比较
*/
public static boolean stackTraceElementIs(StackTraceElement e, String className, String methodName, boolean isNative) { public static boolean stackTraceElementIs(StackTraceElement e, String className, String methodName, boolean isNative) {
return e.getClassName().equals(className) && e.getMethodName().equals(methodName) && e.isNativeMethod() == isNative; return e.getClassName().equals(className) && e.getMethodName().equals(methodName) && e.isNativeMethod() == isNative;
} }
//用于判断某个堆栈是否在等待另一个事件
/**
* /用于判断某个堆栈是否在等待另一个事件
*/
public static boolean isWaitingForNextEvent(StackTraceElement[] currentStack) { public static boolean isWaitingForNextEvent(StackTraceElement[] currentStack) {
return stackTraceElementIs(currentStack[0], "java.lang.Object", "wait", true) && stackTraceElementIs(currentStack[1], "java.lang.Object", "wait", false) && stackTraceElementIs(currentStack[2], "java.awt.EventQueue", "getNextEvent", false); return stackTraceElementIs(currentStack[0], "java.lang.Object", "wait", true) && stackTraceElementIs(currentStack[1], "java.lang.Object", "wait", false) && stackTraceElementIs(currentStack[2], "java.awt.EventQueue", "getNextEvent", false);
} }
//event事件的包装类
/**
* /event事件的包装类
*/
public static class DispatchInfo { public static class DispatchInfo {
// 上一次被打印的堆栈 // 上一次被打印的堆栈
private StackTraceElement[] lastReportedStack; private StackTraceElement[] lastReportedStack;
@ -202,14 +235,19 @@ public final class EventDispatchThreadHangMonitor extends EventQueue {
timer = new Timer("EventDispatchThreadHangMonitor", daemon); timer = new Timer("EventDispatchThreadHangMonitor", daemon);
timer.schedule(new HangChecker(), initialDelayMs, CHECK_INTERVAL_MS); timer.schedule(new HangChecker(), initialDelayMs, CHECK_INTERVAL_MS);
} }
//消除Timer
/**
* /消除Timer
*/
public void stopTimer() { public void stopTimer() {
if (timer != null) { if (timer != null) {
timer.cancel(); timer.cancel();
} }
} }
//定时执行的任务 /**
* /定时执行的任务
*/
public class HangChecker extends TimerTask { public class HangChecker extends TimerTask {
@Override @Override
public void run() { public void run() {
@ -282,7 +320,9 @@ public final class EventDispatchThreadHangMonitor extends EventQueue {
} }
} }
//检查死锁 /**
* 检查死锁
*/
public static void checkForDeadlock() { public static void checkForDeadlock() {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long[] threadIds = threadBean.findDeadlockedThreads(); long[] threadIds = threadBean.findDeadlockedThreads();

5
designer-base/src/main/java/com/fr/design/carton/FeedbackToolboxDialog.java

@ -37,7 +37,9 @@ import java.util.List;
public class FeedbackToolboxDialog extends JDialog { public class FeedbackToolboxDialog extends JDialog {
//输出日志所在地址 /**
* 定时执行的任务
*/
private static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log"); private static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log");
private UIDatePicker uiDatePicker; private UIDatePicker uiDatePicker;
private JPanel generalSettingPanel = null; private JPanel generalSettingPanel = null;
@ -109,6 +111,7 @@ public class FeedbackToolboxDialog extends JDialog {
} }
} }
@Override
public void mouseEntered(MouseEvent evt) { public void mouseEntered(MouseEvent evt) {
Object source = evt.getSource(); Object source = evt.getSource();
if (source instanceof UILabel) { if (source instanceof UILabel) {

20
designer-base/src/main/java/com/fr/design/carton/SwitchForSwingChecker.java

@ -16,11 +16,17 @@ import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
public class SwitchForSwingChecker { public class SwitchForSwingChecker {
//定时任务的开关 /**
* /定时任务的开关
*/
private static boolean checkerTimerSwitch = false; private static boolean checkerTimerSwitch = false;
//简单记录事件执行时间的开关 /**
* /简单记录事件执行时间的开关
*/
private static boolean easyChecker = false; private static boolean easyChecker = false;
//日志存储地址 /**
* /日志存储地址
*/
private static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log"); private static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log");
private static final String EASY_CHECKER_FILE_NAME = "easy_check_log.csv"; private static final String EASY_CHECKER_FILE_NAME = "easy_check_log.csv";
private static final String TIMER_CHECKER_FILE_NAME = "timer_check_log.csv"; private static final String TIMER_CHECKER_FILE_NAME = "timer_check_log.csv";
@ -171,8 +177,12 @@ public class SwitchForSwingChecker {
} }
//date为 2022-09-08的格式
//埋点方法上传卡顿信息入口
/**
* /埋点方法上传卡顿信息入口
date为 2022-09-08的格式
*/
public static List<CartonUploadMessage> uploadJournalLog(Date dateTime) { public static List<CartonUploadMessage> uploadJournalLog(Date dateTime) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
List<CartonUploadMessage> res = new ArrayList<>(); List<CartonUploadMessage> res = new ArrayList<>();

1
designer-base/src/main/java/com/fr/design/gui/date/UIDatePicker.java

@ -266,6 +266,7 @@ public class UIDatePicker extends UIComboBox implements Serializable {
super.firePropertyChange(propertyName, oldValue, newValue); super.firePropertyChange(propertyName, oldValue, newValue);
} }
@Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
if (calendarPanel.getSelectedDate() != null && dateFormat != null) { if (calendarPanel.getSelectedDate() != null && dateFormat != null) {
String strDate = dateFormat.format(calendarPanel.getSelectedDate()); String strDate = dateFormat.format(calendarPanel.getSelectedDate());

2
designer-base/src/main/java/com/fr/env/detect/ui/EnvDetectorAction.java vendored

@ -15,7 +15,7 @@ public class EnvDetectorAction extends UpdateAction {
public EnvDetectorAction() { public EnvDetectorAction() {
this.setName(Toolkit.i18nText("Fine-Design_Basic_Detect_Toolbar_Title")); this.setName(Toolkit.i18nText("Fine-Design_Basic_Carton_Toolbox_Title"));
this.setSmallIcon("com/fr/env/detect/detect_normal.svg"); this.setSmallIcon("com/fr/env/detect/detect_normal.svg");
} }

Loading…
Cancel
Save