|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|