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.ServerConfig;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.DesignerEnvProcessor;
@ -116,7 +117,7 @@ public class DesignUtils {
* @param 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() {
@Override
public void run() {
@ -129,7 +130,8 @@ public class DesignUtils {
while (true) {
try {
if (serverSocket != null) {
Socket socket = serverSocket.accept(); // 接收客户连接
// 接收客户连接
Socket socket = serverSocket.accept();
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
@ -141,8 +143,8 @@ public class DesignUtils {
String path = f.getAbsolutePath();
boolean isMatch = false;
for (int i = 0; i < suffixs.length; i++) {
isMatch = isMatch || path.endsWith(suffixs[i]);
for (String suffix : suffixs) {
isMatch = isMatch || path.endsWith(suffix);
}
if (isMatch) {
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;
import com.fr.base.ServerConfig;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.design.utils.BrowseUtils;
import com.fr.general.ComparatorUtils;
@ -14,29 +15,28 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ServerStarter {
/**
* 预览Demo
* 找默认工作目录不应该按照名字去找而应该按照安装路径因为默认工作目录的名字可能会改变
*/
public static void browserDemoURL() {
if (!WorkContext.getCurrent().isLocal()) {
//有问题,这里拿不到远程的http端口
BrowseUtils.browser(WorkContext.getCurrent().getPath());
}
else if (ComparatorUtils.equals(StableUtils.getInstallHome(), ".")) {//august:供代码使用
} else if (ComparatorUtils.equals(StableUtils.getInstallHome(), ".")) {//august:供代码使用
String web = GeneralContext.getCurrentAppNameOfEnv();
browserURLWithLocalEnv("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + web + "/" + ServerConfig.getInstance().getServletName());
}else{
} else {
initDemoServerAndBrowser();
}
}
private static void initDemoServerAndBrowser() {
try {
FineEmbedServer.start();
} finally {
@ -44,7 +44,7 @@ public class ServerStarter {
BrowseUtils.browser("http://localhost:" + DesignerEnvManager.getEnvManager().getEmbedServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName());
}
}
/**
* 本地环境浏览url
*
@ -52,9 +52,9 @@ public class ServerStarter {
*/
public static void browserURLWithLocalEnv(final String url) {
if(!FineEmbedServerMonitor.getInstance().isComplete()){
if (!FineEmbedServerMonitor.getInstance().isComplete()) {
FineEmbedServerMonitor.getInstance().monitor();
ExecutorService service = Executors.newSingleThreadExecutor();
ExecutorService service = Executors.newSingleThreadExecutor(new NamedThreadFactory("ServerStarter"));
service.submit(new Runnable() {
@Override
@ -68,7 +68,7 @@ public class ServerStarter {
}
});
service.shutdown();
}else{
} else {
FineEmbedServer.start();
BrowseUtils.browser(url);
}

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

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

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

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

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

@ -1,5 +1,6 @@
package com.fr.start;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.bbs.BBSConstants;
import com.fr.event.Event;
@ -38,7 +39,7 @@ public class SplashContext {
private int fetchOnlineTimes = 0;
private String guest = StringUtils.EMPTY;
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("SplashContext"));
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;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.start.SplashFxActionListener;
import com.fr.start.SplashStrategy;
@ -21,7 +22,7 @@ import java.util.concurrent.Executors;
public class SplashFx implements SplashStrategy {
private SplashFxWindow fxWindow;
private static final ExecutorService SERVICE = Executors.newSingleThreadExecutor();
private static final ExecutorService SERVICE = Executors.newSingleThreadExecutor(new NamedThreadFactory("SplashFx"));
@Override
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.process.ProcessOperator;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.actions.NewFormAction;
import com.fr.design.actions.core.ActionFactory;
@ -169,7 +170,7 @@ public class DesignerActivator extends Activator {
}
private static void preLoadPane() {
ExecutorService service = Executors.newCachedThreadPool();
ExecutorService service = Executors.newCachedThreadPool(new NamedThreadFactory("PreLoadPane"));
service.submit(new Runnable() {
@Override
public void run() {

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

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

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

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

Loading…
Cancel
Save