Browse Source

REPORT-18494 线程池命名

research/10.0
vito 6 years ago
parent
commit
9194307c92
  1. 10
      designer-base/src/main/java/com/fr/design/utils/DesignUtils.java
  2. 22
      designer-base/src/main/java/com/fr/start/ServerStarter.java
  3. 3
      designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java
  4. 3
      designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java
  5. 3
      designer-realize/src/main/java/com/fr/start/SplashContext.java
  6. 3
      designer-realize/src/main/java/com/fr/start/fx/SplashFx.java
  7. 3
      designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java
  8. 41
      designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java
  9. 71
      designer-realize/src/main/java/com/fr/start/module/PreStartActivator.java
  10. 3
      designer-realize/src/main/java/com/fr/start/preload/ImagePreLoader.java

10
designer-base/src/main/java/com/fr/design/utils/DesignUtils.java

@ -2,6 +2,7 @@ package com.fr.design.utils;
import com.fr.base.FeedBackInfo; import com.fr.base.FeedBackInfo;
import com.fr.base.ServerConfig; import com.fr.base.ServerConfig;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.fun.DesignerEnvProcessor;
@ -116,7 +117,7 @@ public class DesignUtils {
* @param suffixs 文件后缀 * @param suffixs 文件后缀
*/ */
public static void createListeningServer(final int startPort, final String[] suffixs) { public static void createListeningServer(final int startPort, final String[] suffixs) {
ExecutorService service = Executors.newSingleThreadExecutor(); ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("DesignClientListener"));
service.execute(new Runnable() { service.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -129,7 +130,8 @@ public class DesignUtils {
while (true) { while (true) {
try { try {
if (serverSocket != null) { if (serverSocket != null) {
Socket socket = serverSocket.accept(); // 接收客户连接 // 接收客户连接
Socket socket = serverSocket.accept();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
@ -141,8 +143,8 @@ public class DesignUtils {
String path = f.getAbsolutePath(); String path = f.getAbsolutePath();
boolean isMatch = false; boolean isMatch = false;
for (int i = 0; i < suffixs.length; i++) { for (String suffix : suffixs) {
isMatch = isMatch || path.endsWith(suffixs[i]); isMatch = isMatch || path.endsWith(suffix);
} }
if (isMatch) { if (isMatch) {
DesignerContext.getDesignerFrame().openTemplate(new FileFILE(f)); DesignerContext.getDesignerFrame().openTemplate(new FileFILE(f));

22
designer-base/src/main/java/com/fr/start/ServerStarter.java

@ -1,6 +1,7 @@
package com.fr.start; package com.fr.start;
import com.fr.base.ServerConfig; import com.fr.base.ServerConfig;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.utils.BrowseUtils; import com.fr.design.utils.BrowseUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -14,29 +15,28 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class ServerStarter { public class ServerStarter {
/** /**
* 预览Demo * 预览Demo
* 找默认工作目录不应该按照名字去找而应该按照安装路径因为默认工作目录的名字可能会改变 * 找默认工作目录不应该按照名字去找而应该按照安装路径因为默认工作目录的名字可能会改变
*/ */
public static void browserDemoURL() { public static void browserDemoURL() {
if (!WorkContext.getCurrent().isLocal()) { if (!WorkContext.getCurrent().isLocal()) {
//有问题,这里拿不到远程的http端口 //有问题,这里拿不到远程的http端口
BrowseUtils.browser(WorkContext.getCurrent().getPath()); BrowseUtils.browser(WorkContext.getCurrent().getPath());
} } else if (ComparatorUtils.equals(StableUtils.getInstallHome(), ".")) {//august:供代码使用
else if (ComparatorUtils.equals(StableUtils.getInstallHome(), ".")) {//august:供代码使用
String web = GeneralContext.getCurrentAppNameOfEnv(); String web = GeneralContext.getCurrentAppNameOfEnv();
browserURLWithLocalEnv("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + web + "/" + ServerConfig.getInstance().getServletName()); browserURLWithLocalEnv("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + web + "/" + ServerConfig.getInstance().getServletName());
}else{ } else {
initDemoServerAndBrowser(); initDemoServerAndBrowser();
} }
} }
private static void initDemoServerAndBrowser() { private static void initDemoServerAndBrowser() {
try { try {
FineEmbedServer.start(); FineEmbedServer.start();
} finally { } finally {
@ -44,7 +44,7 @@ public class ServerStarter {
BrowseUtils.browser("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName()); BrowseUtils.browser("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName());
} }
} }
/** /**
* 本地环境浏览url * 本地环境浏览url
* *
@ -52,9 +52,9 @@ public class ServerStarter {
*/ */
public static void browserURLWithLocalEnv(final String url) { public static void browserURLWithLocalEnv(final String url) {
if(!FineEmbedServerMonitor.getInstance().isComplete()){ if (!FineEmbedServerMonitor.getInstance().isComplete()) {
FineEmbedServerMonitor.getInstance().monitor(); FineEmbedServerMonitor.getInstance().monitor();
ExecutorService service = Executors.newSingleThreadExecutor(); ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("ServerStarter"));
service.submit(new Runnable() { service.submit(new Runnable() {
@Override @Override
@ -68,7 +68,7 @@ public class ServerStarter {
} }
}); });
service.shutdown(); service.shutdown();
}else{ } else {
FineEmbedServer.start(); FineEmbedServer.start();
BrowseUtils.browser(url); BrowseUtils.browser(url);
} }

3
designer-base/src/main/java/com/fr/start/server/FineEmbedServerMonitor.java

@ -1,5 +1,6 @@
package com.fr.start.server; package com.fr.start.server;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.event.Event; import com.fr.event.Event;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
@ -66,7 +67,7 @@ public class FineEmbedServerMonitor {
} }
public void monitor() { public void monitor() {
ExecutorService service = Executors.newSingleThreadExecutor(); ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("FineEmbedServerMonitor"));
service.submit(new Runnable() { service.submit(new Runnable() {
@Override @Override

3
designer-realize/src/main/java/com/fr/design/mainframe/InformationCollector.java

@ -4,6 +4,7 @@
package com.fr.design.mainframe; package com.fr.design.mainframe;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.config.MarketConfig; import com.fr.config.MarketConfig;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.errorinfo.ErrorInfoUploader; import com.fr.design.mainframe.errorinfo.ErrorInfoUploader;
@ -196,7 +197,7 @@ public class InformationCollector implements XMLReadable, XMLWriter {
return; return;
} }
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("InformationCollector"));
service.schedule(new Runnable() { service.schedule(new Runnable() {
@Override @Override
public void run() { public void run() {

3
designer-realize/src/main/java/com/fr/start/SplashContext.java

@ -1,5 +1,6 @@
package com.fr.start; package com.fr.start;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.bbs.BBSConstants; import com.fr.design.mainframe.bbs.BBSConstants;
import com.fr.event.Event; import com.fr.event.Event;
@ -38,7 +39,7 @@ public class SplashContext {
private int fetchOnlineTimes = 0; private int fetchOnlineTimes = 0;
private String guest = StringUtils.EMPTY; private String guest = StringUtils.EMPTY;
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("SplashContext"));
private Listener<String> listener; private Listener<String> listener;

3
designer-realize/src/main/java/com/fr/start/fx/SplashFx.java

@ -1,5 +1,6 @@
package com.fr.start.fx; package com.fr.start.fx;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.start.SplashFxActionListener; import com.fr.start.SplashFxActionListener;
import com.fr.start.SplashStrategy; import com.fr.start.SplashStrategy;
@ -21,7 +22,7 @@ import java.util.concurrent.Executors;
public class SplashFx implements SplashStrategy { public class SplashFx implements SplashStrategy {
private SplashFxWindow fxWindow; private SplashFxWindow fxWindow;
private static final ExecutorService SERVICE = Executors.newSingleThreadExecutor(); private static final ExecutorService SERVICE = Executors.newSingleThreadExecutor(new NamedThreadFactory("SplashFx"));
@Override @Override
public void show() { public void show() {

3
designer-realize/src/main/java/com/fr/start/module/DesignerActivator.java

@ -5,6 +5,7 @@ import com.fr.base.Formula;
import com.fr.base.MultiFieldParameter; import com.fr.base.MultiFieldParameter;
import com.fr.base.process.ProcessOperator; import com.fr.base.process.ProcessOperator;
import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.ChartCollection;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.NewFormAction; import com.fr.design.actions.NewFormAction;
import com.fr.design.actions.core.ActionFactory; import com.fr.design.actions.core.ActionFactory;
@ -169,7 +170,7 @@ public class DesignerActivator extends Activator {
} }
private static void preLoadPane() { private static void preLoadPane() {
ExecutorService service = Executors.newCachedThreadPool(); ExecutorService service = Executors.newCachedThreadPool(new NamedThreadFactory("PreLoadPane"));
service.submit(new Runnable() { service.submit(new Runnable() {
@Override @Override
public void run() { public void run() {

41
designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceActivator.java

@ -1,5 +1,6 @@
package com.fr.start.module; package com.fr.start.module;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.HistoryTemplateListCache;
import com.fr.event.Event; import com.fr.event.Event;
import com.fr.event.Listener; import com.fr.event.Listener;
@ -16,79 +17,77 @@ import java.util.concurrent.Executors;
* Created by juhaoyu on 2019-06-14. * Created by juhaoyu on 2019-06-14.
*/ */
public class DesignerWorkspaceActivator extends Activator { public class DesignerWorkspaceActivator extends Activator {
@Override @Override
public void start() { public void start() {
registerEnvListener(); registerEnvListener();
startServer(WorkContext.getCurrent()); startServer(WorkContext.getCurrent());
} }
/** /**
* 注册切换环境前后事件监听 * 注册切换环境前后事件监听
*/ */
private void registerEnvListener() { private void registerEnvListener() {
/*切换环境前,关闭所有相关模块,最后执行*/ /*切换环境前,关闭所有相关模块,最后执行*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MIN_VALUE) { listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override @Override
public void on(Event event, Workspace current) { public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).stop(); getSub(EnvBasedModule.class).stop();
} }
}); });
/*切换环境后,重新启动所有相关模块,最先执行*/ /*切换环境后,重新启动所有相关模块,最先执行*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MAX_VALUE) { listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override @Override
public void on(Event event, Workspace current) { public void on(Event event, Workspace current) {
getSub(EnvBasedModule.class).start(); getSub(EnvBasedModule.class).start();
startServer(current); startServer(current);
} }
}); });
/*切换环境前,存储一下打开的所有文件对象,要先于 关闭相关模块部分 被触发*/ /*切换环境前,存储一下打开的所有文件对象,要先于 关闭相关模块部分 被触发*/
listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MAX_VALUE) { listenEvent(WorkspaceEvent.BeforeSwitch, new Listener<Workspace>(Integer.MAX_VALUE) {
@Override @Override
public void on(Event event, Workspace workspace) { public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().stash(); HistoryTemplateListCache.getInstance().stash();
} }
}); });
/*切换环境后,装载一下打开的所有文件对象,优先级低于默认优先级,要后于 启动相关模块部分 被触发*/ /*切换环境后,装载一下打开的所有文件对象,优先级低于默认优先级,要后于 启动相关模块部分 被触发*/
listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MIN_VALUE) { listenEvent(WorkspaceEvent.AfterSwitch, new Listener<Workspace>(Integer.MIN_VALUE) {
@Override @Override
public void on(Event event, Workspace workspace) { public void on(Event event, Workspace workspace) {
HistoryTemplateListCache.getInstance().load(); HistoryTemplateListCache.getInstance().load();
} }
}); });
} }
private void startServer(Workspace current) { private void startServer(Workspace current) {
// 切换后的环境是本地环境才启动内置服务器 // 切换后的环境是本地环境才启动内置服务器
if (current.isLocal()) { if (current.isLocal()) {
ExecutorService service = Executors.newSingleThreadExecutor(); ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("DesignerWorkspaceActivator"));
service.submit(new Runnable() { service.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
FineEmbedServer.start(); FineEmbedServer.start();
} }
}); });
service.shutdown(); service.shutdown();
} }
} }
@Override @Override
public void stop() { public void stop() {
} }
} }

71
designer-realize/src/main/java/com/fr/start/module/PreStartActivator.java

@ -1,5 +1,6 @@
package com.fr.start.module; package com.fr.start.module;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.RestartHelper; import com.fr.design.RestartHelper;
import com.fr.design.fun.OemProcessor; import com.fr.design.fun.OemProcessor;
@ -33,10 +34,10 @@ import java.util.concurrent.Executors;
* Created by juhaoyu on 2018/1/8. * Created by juhaoyu on 2018/1/8.
*/ */
public class PreStartActivator extends Activator { public class PreStartActivator extends Activator {
@Override @Override
public void start() { public void start() {
BuildContext.setBuildFilePath("/com/fr/stable/build.properties"); BuildContext.setBuildFilePath("/com/fr/stable/build.properties");
// 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了 // 如果端口被占用了 说明程序已经运行了一次,也就是说,已经建立一个监听服务器,现在只要给服务器发送命令就好了
final String[] args = getModule().upFindSingleton(StartupArgs.class).get(); final String[] args = getModule().upFindSingleton(StartupArgs.class).get();
@ -48,98 +49,98 @@ public class PreStartActivator extends Activator {
System.exit(0); System.exit(0);
return; return;
} }
RestartHelper.deleteRecordFilesWhenStart(); RestartHelper.deleteRecordFilesWhenStart();
preloadResource(); preloadResource();
SplashContext.getInstance().registerSplash(createSplash()); SplashContext.getInstance().registerSplash(createSplash());
SplashContext.getInstance().show(); SplashContext.getInstance().show();
//初始化 //初始化
EventDispatcher.fire(ModuleEvent.MajorModuleStarting, Toolkit.i18nText("Fine-Design_Basic_Initializing")); EventDispatcher.fire(ModuleEvent.MajorModuleStarting, Toolkit.i18nText("Fine-Design_Basic_Initializing"));
// 完成初始化 // 完成初始化
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
CloudCenter.getInstance(); CloudCenter.getInstance();
// 创建监听服务 // 创建监听服务
DesignUtils.createListeningServer(DesignUtils.getPort(), startFileSuffix()); DesignUtils.createListeningServer(DesignUtils.getPort(), startFileSuffix());
initLanguage(); initLanguage();
} }
@Override @Override
public void stop() { public void stop() {
} }
private void checkDebugStart() { private void checkDebugStart() {
if (isDebug()) { if (isDebug()) {
setDebugEnv(); setDebugEnv();
} }
} }
/** /**
* 在VM options里加入-Ddebug=true激活 * 在VM options里加入-Ddebug=true激活
* *
* @return isDebug * @return isDebug
*/ */
private boolean isDebug() { private boolean isDebug() {
return ComparatorUtils.equals("true", System.getProperty("debug")); return ComparatorUtils.equals("true", System.getProperty("debug"));
} }
//端口改一下,环境配置文件改一下。便于启动两个设计器,进行对比调试 //端口改一下,环境配置文件改一下。便于启动两个设计器,进行对比调试
private void setDebugEnv() { private void setDebugEnv() {
DesignUtils.setPort(DesignerPort.DEBUG_MESSAGE_PORT); DesignUtils.setPort(DesignerPort.DEBUG_MESSAGE_PORT);
String debugXMlFilePath = StableUtils.pathJoin( String debugXMlFilePath = StableUtils.pathJoin(
ProductConstants.getEnvHome(), ProductConstants.getEnvHome(),
ProductConstants.APP_NAME + "Env_debug.xml" ProductConstants.APP_NAME + "Env_debug.xml"
); );
DesignerEnvManager.setEnvFile( DesignerEnvManager.setEnvFile(
new File(debugXMlFilePath)); new File(debugXMlFilePath));
} }
private void initLanguage() { private void initLanguage() {
//这两句的位置不能随便调换,因为会影响语言切换的问题 //这两句的位置不能随便调换,因为会影响语言切换的问题
GeneralContext.setLocale(DesignerEnvManager.getEnvManager(false).getLanguage()); GeneralContext.setLocale(DesignerEnvManager.getEnvManager(false).getLanguage());
} }
private String[] startFileSuffix() { private String[] startFileSuffix() {
return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"}; return new String[]{".cpt", ".xls", ".xlsx", ".frm", ".form", ".cht", ".chart"};
} }
private static void preloadResource() { private static void preloadResource() {
ExecutorService service = Executors.newCachedThreadPool(); ExecutorService service = Executors.newCachedThreadPool(new NamedThreadFactory("PreLoadResource"));
service.submit(new Runnable() { service.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
new ImagePreLoader(); new ImagePreLoader();
} }
}); });
service.submit(new Runnable() { service.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
TemplateInfoCollector.getInstance(); TemplateInfoCollector.getInstance();
} }
}); });
service.shutdown(); service.shutdown();
} }
private SplashStrategy createSplash() { private SplashStrategy createSplash() {
OemProcessor oemProcessor = OemHandler.findOem(); OemProcessor oemProcessor = OemHandler.findOem();
if (oemProcessor != null) { if (oemProcessor != null) {
SplashStrategy splashStrategy = null; SplashStrategy splashStrategy = null;

3
designer-realize/src/main/java/com/fr/start/preload/ImagePreLoader.java

@ -1,5 +1,6 @@
package com.fr.start.preload; package com.fr.start.preload;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.general.IOUtils; import com.fr.general.IOUtils;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -13,7 +14,7 @@ public class ImagePreLoader {
public static final int THRESHOLD = 50; public static final int THRESHOLD = 50;
public ImagePreLoader() { public ImagePreLoader() {
ExecutorService service = Executors.newCachedThreadPool(); ExecutorService service = Executors.newCachedThreadPool(new NamedThreadFactory("ImagePreLoader"));
int len = preLoadImages.length; int len = preLoadImages.length;
int start = 0; int start = 0;

Loading…
Cancel
Save