|
|
|
@ -10,13 +10,17 @@ import com.fr.log.FineLoggerFactory;
|
|
|
|
|
import com.fr.stable.ProductConstantsBase; |
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.xml.XMLPrintWriter; |
|
|
|
|
import com.fr.stable.xml.XMLReadable; |
|
|
|
|
import com.fr.stable.xml.XMLWriter; |
|
|
|
|
import com.fr.stable.xml.XMLableReader; |
|
|
|
|
import sun.awt.AppContext; |
|
|
|
|
|
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
import java.io.FileReader; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
@ -25,13 +29,21 @@ import java.util.Map;
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.Calendar; |
|
|
|
|
|
|
|
|
|
public class SwitchForSwingChecker { |
|
|
|
|
public class SwitchForSwingChecker implements XMLReadable, XMLWriter { |
|
|
|
|
/** |
|
|
|
|
* /定时任务的开关 |
|
|
|
|
* Designer4Debug类名 |
|
|
|
|
*/ |
|
|
|
|
private static final String DEBUG_MAIN_CLASS_NAME = "com.fr.start.Designer4Debug"; |
|
|
|
|
/** |
|
|
|
|
* XML标签 |
|
|
|
|
*/ |
|
|
|
|
public static final String XML_TAG = "SwitchForSwingChecker"; |
|
|
|
|
/** |
|
|
|
|
* 定时任务的开关 |
|
|
|
|
*/ |
|
|
|
|
private static boolean checkerTimerSwitch = false; |
|
|
|
|
/** |
|
|
|
|
* /简单记录事件执行时间的开关 |
|
|
|
|
* 简单记录事件执行时间的开关 |
|
|
|
|
*/ |
|
|
|
|
private static boolean easyChecker = false; |
|
|
|
|
/** |
|
|
|
@ -41,7 +53,7 @@ public class SwitchForSwingChecker {
|
|
|
|
|
public static final int EASY_CHECK_FLAG = 1; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* /日志存储地址 |
|
|
|
|
* 日志存储地址 |
|
|
|
|
*/ |
|
|
|
|
public static final String JOURNAL_FILE_PATH = StableUtils.pathJoin(ProductConstantsBase.getEnvHome(), "journal_log"); |
|
|
|
|
public static final String EASY_CHECKER_FILE_NAME = "easy_check_log.csv"; |
|
|
|
@ -54,12 +66,21 @@ public class SwitchForSwingChecker {
|
|
|
|
|
return easyChecker; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static volatile SwitchForSwingChecker switchForSwingChecker = new SwitchForSwingChecker(); |
|
|
|
|
|
|
|
|
|
public static SwitchForSwingChecker getInstance() { |
|
|
|
|
return switchForSwingChecker; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void startTimerChecker() { |
|
|
|
|
if (!checkerTimerSwitch) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.initTimer(); |
|
|
|
|
CartonThreadExecutorPool.getTimerThreadExecutorPool().initTimer(); |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.setTimerWitch(true); |
|
|
|
|
checkerTimerSwitch = true; |
|
|
|
|
if (!easyChecker) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.startFilterModalWindow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -69,6 +90,9 @@ public class SwitchForSwingChecker {
|
|
|
|
|
CartonThreadExecutorPool.getTimerThreadExecutorPool().stopTimer(); |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.setTimerWitch(false); |
|
|
|
|
checkerTimerSwitch = false; |
|
|
|
|
if (!easyChecker) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.stopFilterModalWindow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -77,6 +101,9 @@ public class SwitchForSwingChecker {
|
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.setEasyWitch(true); |
|
|
|
|
CartonThreadExecutorPool.getTimerThreadExecutorPool().setEasyWitch(true); |
|
|
|
|
easyChecker = true; |
|
|
|
|
if (!checkerTimerSwitch) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.startFilterModalWindow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -85,6 +112,9 @@ public class SwitchForSwingChecker {
|
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.setEasyWitch(false); |
|
|
|
|
CartonThreadExecutorPool.getTimerThreadExecutorPool().setEasyWitch(false); |
|
|
|
|
easyChecker = false; |
|
|
|
|
if (!checkerTimerSwitch) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.stopFilterModalWindow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -215,10 +245,15 @@ public class SwitchForSwingChecker {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化监控任务,主要是替换EventQueue以及SwingWorker执行任务的线程池 |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
public static void initThreadMonitoring () { |
|
|
|
|
EventDispatchThreadHangMonitor.initMonitoring(); |
|
|
|
|
AppContext.getAppContext().put(SwingWorker.class, CartonThreadExecutorPool.getTimerThreadExecutorPool()); |
|
|
|
|
String mainClass = System.getProperty("sun.java.command"); |
|
|
|
|
//判断一下,如果是以Designer4Debug启动,就不注册代码,不然会覆盖掉SwingExplorer,导致其无法使用
|
|
|
|
|
if (!StringUtils.equals(mainClass, DEBUG_MAIN_CLASS_NAME)) { |
|
|
|
|
EventDispatchThreadHangMonitor.initMonitoring(); |
|
|
|
|
AppContext.getAppContext().put(SwingWorker.class, CartonThreadExecutorPool.getTimerThreadExecutorPool()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -237,4 +272,40 @@ public class SwitchForSwingChecker {
|
|
|
|
|
public static boolean isCartonExists() { |
|
|
|
|
return isCartonExists(new Date()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initSwitchChecker() { |
|
|
|
|
if (easyChecker) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.setEasyWitch(true); |
|
|
|
|
CartonThreadExecutorPool.getTimerThreadExecutorPool().setEasyWitch(true); |
|
|
|
|
} |
|
|
|
|
if (checkerTimerSwitch) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.initTimer(); |
|
|
|
|
CartonThreadExecutorPool.getTimerThreadExecutorPool().initTimer(); |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.setTimerWitch(true); |
|
|
|
|
} |
|
|
|
|
if (easyChecker || checkerTimerSwitch) { |
|
|
|
|
EventDispatchThreadHangMonitor.INSTANCE.startFilterModalWindow(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void readXML(XMLableReader reader) { |
|
|
|
|
if (reader.isAttr()) { |
|
|
|
|
checkerTimerSwitch = reader.getAttrAsBoolean("checkerTimerSwitch", false); |
|
|
|
|
easyChecker = reader.getAttrAsBoolean("easyChecker", false); |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
initSwitchChecker(); |
|
|
|
|
} catch (Throwable t) { |
|
|
|
|
FineLoggerFactory.getLogger().error("read checker attr fail", t); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void writeXML(XMLPrintWriter writer) { |
|
|
|
|
writer.startTAG(XML_TAG); |
|
|
|
|
writer.attr("checkerTimerSwitch", checkerTimerSwitch); |
|
|
|
|
writer.attr("easyChecker", easyChecker); |
|
|
|
|
writer.end(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|