Browse Source

REPORT-83197【设计器】启动页性能优化

将异步功能放到 UIUtil 中去执行。避免多线程问题
feature/x
Harrison 2 years ago
parent
commit
0f33a0fee9
  1. 36
      designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java
  2. 29
      designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java

36
designer-base/src/main/java/com/fr/design/actions/core/ActionFactory.java

@ -6,12 +6,10 @@ import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.menu.MenuKeySet;
import com.fr.design.selection.QuickEditor;
import com.fr.design.ui.util.UIUtil;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import com.fr.start.common.DesignerStartupPool;
import com.fr.third.guava.util.concurrent.FutureCallback;
import com.fr.third.guava.util.concurrent.Futures;
import com.fr.third.guava.util.concurrent.ListenableFutureTask;
import javax.swing.Action;
import javax.swing.KeyStroke;
@ -22,7 +20,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArraySet;
@ -86,23 +84,19 @@ public class ActionFactory {
public static void registerAsyncInitCellEditorClass(Class keyClazz, Class<? extends QuickEditor> editorClazz) {
cellEditorClass.put(keyClazz, editorClazz);
Callable<QuickEditor> callable = new Callable<QuickEditor>() {
@Override
public QuickEditor call() throws Exception {
return editorClazz.newInstance();
}
};
ListenableFutureTask<QuickEditor> future = ListenableFutureTask.create(callable);
Futures.addCallback(future, new FutureCallback<QuickEditor>() {
@Override
public void onSuccess(QuickEditor quickEditor) {
cellEditorClass.remove(keyClazz);
cellEditor.put(keyClazz, quickEditor);
}
@Override
public void onFailure(Throwable throwable) {
}
CompletableFuture.runAsync(() -> {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
try {
QuickEditor quickEditor = editorClazz.newInstance();
cellEditorClass.remove(keyClazz);
cellEditor.put(keyClazz, quickEditor);
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
});
}, DesignerStartupPool.designer());
}

29
designer-base/src/main/java/com/fr/startup/ui/StartupLoadingPanel.java

@ -4,7 +4,7 @@ import com.fr.concurrent.FineExecutors;
import com.fr.concurrent.NamedThreadFactory;
import com.fr.design.gui.iprogressbar.ProgressDialog;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.ui.util.UIUtil;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
@ -68,19 +68,20 @@ public class StartupLoadingPanel {
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (isComplete()) {
scheduler.shutdown();
progressDialog.dispose();
resetListeners();
return;
}
if (!progressDialog.isVisible()) {
progressDialog = new ProgressDialog(DesignerContext.getDesignerFrame());
progressDialog.setVisible(true);
String moduleId = getModuleId();
progressDialog.updateLoadingText(moduleId);
}
progressDialog.setProgressValue(incrementProgress());
UIUtil.invokeAndWaitIfNeeded(() -> {
if (isComplete()) {
scheduler.shutdown();
progressDialog.dispose();
resetListeners();
return;
}
if (!progressDialog.isVisible()) {
progressDialog.setVisible(true);
String moduleId = getModuleId();
progressDialog.updateLoadingText(moduleId);
}
progressDialog.setProgressValue(incrementProgress());
});
}
}, 0, STEP_HEARTBEAT, TimeUnit.MILLISECONDS);

Loading…
Cancel
Save