diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java index bb98fdeffa..e174cd16fc 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/TableDataTreeSearchManager.java @@ -131,7 +131,7 @@ public class TableDataTreeSearchManager { * @param searchText */ public void startSearch(String searchText) { - if (isRepeatSearch(searchText)) { + if (isRepeatSearch(searchText) || StringUtils.isEmpty(searchText)) { return; } setTreeSearchStatus(TreeSearchStatus.SEARCHING); @@ -196,6 +196,7 @@ public class TableDataTreeSearchManager { */ public void restoreToolBarAndTreePane() { setTreeSearchStatus(TreeSearchStatus.NOT_IN_SEARCH_MODE); + TableDataSearchTimer.getInstance().stopClock(); if (treeSearcher != null) { treeSearcher.afterSearch(); } @@ -210,6 +211,7 @@ public class TableDataTreeSearchManager { */ public void restoreTreePane() { setTreeSearchStatus(TreeSearchStatus.SEARCH_NOT_BEGIN); + TableDataSearchTimer.getInstance().stopClock(); lastSearchText = null; if (rendererHelper != null) { rendererHelper.restore(getCurrentTableDataTree()); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java index 160d462b47..4d9d458c95 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/searcher/TableDataTreeSearcher.java @@ -75,7 +75,7 @@ public class TableDataTreeSearcher implements TreeSearcher { * @param tableDataSource */ public void beforeSearch(TableDataSearchMode searchMode, TableDataSource tableDataSource) { - executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory(TableDataTreeSearchManager.class)); + executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory(TableDataTreeSearcher.class)); collectTableDataWrappers(searchMode, tableDataSource); preCalculateColumns(); } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimer.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimer.java index 88c305e98b..1b6057983f 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimer.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimer.java @@ -1,6 +1,9 @@ package com.fr.design.data.datapane.management.search.time; import com.fr.concurrent.NamedThreadFactory; +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralUtils; +import com.fr.third.org.apache.commons.lang3.ObjectUtils; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -16,7 +19,7 @@ public class TableDataSearchTimer { /** * 定时器 */ - private ScheduledExecutorService scheduler; + private static ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(TableDataSearchTimer.class)); /** * 定时任务 @@ -40,15 +43,24 @@ public class TableDataSearchTimer { } public void startClock() { - this.scheduler = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(TableDataSearchTimer.class)); this.timeTask = new TableDataSearchTimerTask(); scheduler.schedule(timeTask, MAX_SEARCH_TIME, TimeUnit.MILLISECONDS); } public void stopClock() { this.timeTask = null; - if (this.scheduler != null) { - this.scheduler.shutdownNow(); - } + } + + public void shutdown() { + scheduler.shutdown(); + } + + /** + * 判断是不是当前的Timer中的task,为了避免shutdownNow()之后原task仍在执行,可能会 + * @param task + * @return + */ + public boolean isCurrentTask(TableDataSearchTimerTask task) { + return ComparatorUtils.equals(this.timeTask, task); } } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimerTask.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimerTask.java index 65c2a04580..27b074f7e3 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimerTask.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/time/TableDataSearchTimerTask.java @@ -14,7 +14,8 @@ public class TableDataSearchTimerTask implements Runnable { @Override public void run() { // 最大单次搜索时间过后,将结束搜索 - if (TableDataTreeSearchManager.getInstance().getTreeSearchStatus() == TreeSearchStatus.SEARCHING) { + if (TableDataTreeSearchManager.getInstance().getTreeSearchStatus() == TreeSearchStatus.SEARCHING && + TableDataSearchTimer.getInstance().isCurrentTask(this)) { TableDataTreeSearchManager.getInstance().completeSearch(); } }