feat(任务监控): 添加Executor信息监控面板并重构界面
重构任务监控界面布局,将演示任务功能移至监控窗口工具栏 新增Executor信息监控面板,显示线程池详细状态信息 移除主界面中的演示任务按钮,更新项目版本号
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -10,7 +10,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>com.ecep.contract</groupId>
|
<groupId>com.ecep.contract</groupId>
|
||||||
<artifactId>Contract-Manager</artifactId>
|
<artifactId>Contract-Manager</artifactId>
|
||||||
<version>0.0.45-SNAPSHOT</version>
|
<version>0.0.46-SNAPSHOT</version>
|
||||||
<name>Contract-Manager</name>
|
<name>Contract-Manager</name>
|
||||||
<description>Contract-Manager</description>
|
<description>Contract-Manager</description>
|
||||||
<url/>
|
<url/>
|
||||||
|
|||||||
@@ -220,13 +220,4 @@ public class HomeWindowController extends BaseController {
|
|||||||
public void onShowTaskMonitorWindowAction(ActionEvent event) {
|
public void onShowTaskMonitorWindowAction(ActionEvent event) {
|
||||||
showInOwner(TaskMonitorViewController.class);
|
showInOwner(TaskMonitorViewController.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 运行任务监控演示
|
|
||||||
*/
|
|
||||||
public void onRunTaskMonitorDemo(ActionEvent event) {
|
|
||||||
com.ecep.contract.manager.ui.task.DemoTask.runDemo();
|
|
||||||
// 自动打开任务监控窗口
|
|
||||||
showInOwner(TaskMonitorViewController.class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ public class TaskMonitorCenter {
|
|||||||
tooltip.setText("当前运行任务数: " + activeTasks.size());
|
tooltip.setText("当前运行任务数: " + activeTasks.size());
|
||||||
});
|
});
|
||||||
monitorLabel.setOnMouseClicked(event -> {
|
monitorLabel.setOnMouseClicked(event -> {
|
||||||
BaseController.show(TaskMonitorViewController.class, monitorLabel.getScene().getWindow());
|
BaseController.show(TaskMonitorViewController.class, monitorLabel.getScene().getWindow());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package com.ecep.contract.manager.ui.task;
|
package com.ecep.contract.manager.ui.task;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
@@ -13,6 +17,7 @@ import com.ecep.contract.manager.ui.Message;
|
|||||||
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
import com.ecep.contract.manager.util.MyDateTimeUtils;
|
||||||
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
@@ -30,6 +35,7 @@ import javafx.scene.layout.HBox;
|
|||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
import javafx.stage.WindowEvent;
|
import javafx.stage.WindowEvent;
|
||||||
|
|
||||||
@@ -69,10 +75,47 @@ public class TaskMonitorViewController extends BaseController {
|
|||||||
private Button cancelTaskButton;
|
private Button cancelTaskButton;
|
||||||
@FXML
|
@FXML
|
||||||
private Button clearHistoryButton;
|
private Button clearHistoryButton;
|
||||||
|
@FXML
|
||||||
|
private Button refreshExecutorInfoButton;
|
||||||
|
@FXML
|
||||||
|
private TableView<ExecutorInfo> executorInfoTable;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ExecutorInfo, String> executorFieldColumn;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ExecutorInfo, String> executorValueColumn;
|
||||||
|
@FXML
|
||||||
|
private TableColumn<ExecutorInfo, String> executorDescriptionColumn;
|
||||||
|
|
||||||
public TaskMonitorViewController() {
|
public TaskMonitorViewController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于存储ExecutorService信息的内部类
|
||||||
|
*/
|
||||||
|
public static class ExecutorInfo {
|
||||||
|
private final String field;
|
||||||
|
private final String value;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
public ExecutorInfo(String field, String value, String description) {
|
||||||
|
this.field = field;
|
||||||
|
this.value = value;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getField() {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShown(WindowEvent windowEvent) {
|
public void onShown(WindowEvent windowEvent) {
|
||||||
super.onShown(windowEvent);
|
super.onShown(windowEvent);
|
||||||
@@ -144,6 +187,94 @@ public class TaskMonitorViewController extends BaseController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
cancelTaskButton.disableProperty().bind(activeTasksTable.getSelectionModel().selectedItemProperty().isNull());
|
cancelTaskButton.disableProperty().bind(activeTasksTable.getSelectionModel().selectedItemProperty().isNull());
|
||||||
|
// 初始化Executor信息表格
|
||||||
|
initializeExecutorInfoTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化Executor信息表格
|
||||||
|
*/
|
||||||
|
private void initializeExecutorInfoTable() {
|
||||||
|
executorFieldColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getField()));
|
||||||
|
executorValueColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue()));
|
||||||
|
executorDescriptionColumn
|
||||||
|
.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getDescription()));
|
||||||
|
|
||||||
|
// 初始加载Executor信息
|
||||||
|
refreshExecutorInfo();
|
||||||
|
// 绑定刷新按钮事件
|
||||||
|
refreshExecutorInfoButton.setOnAction(event -> refreshExecutorInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新Executor信息
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void refreshExecutorInfo() {
|
||||||
|
executorInfoTable.getItems().clear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ExecutorService executorService = Desktop.instance.getExecutorService();
|
||||||
|
if (executorService instanceof ThreadPoolExecutor threadPoolExecutor) {
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"PoolSize",
|
||||||
|
String.valueOf(threadPoolExecutor.getPoolSize()),
|
||||||
|
"PoolSize"));
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"活动线程数",
|
||||||
|
String.valueOf(threadPoolExecutor.getActiveCount()),
|
||||||
|
"当前正在执行任务的线程数"));
|
||||||
|
// 添加线程池信息
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"核心线程数",
|
||||||
|
String.valueOf(threadPoolExecutor.getCorePoolSize()),
|
||||||
|
"线程池维护的最小线程数"));
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"最大线程数",
|
||||||
|
String.valueOf(threadPoolExecutor.getMaximumPoolSize()),
|
||||||
|
"线程池允许的最大线程数"));
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"KeepAliveTime",
|
||||||
|
String.valueOf(threadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS)),
|
||||||
|
"the thread keep-alive time, which is the amount of time that threads may remain idle before being terminated. Threads that wait this amount of time without processing a task will be terminated if there are more than the core number of threads currently in the pool, or if this pool allows core thread timeout."));
|
||||||
|
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"任务队列大小",
|
||||||
|
String.valueOf(threadPoolExecutor.getQueue().size()),
|
||||||
|
"等待执行的任务数量"));
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"已完成任务数",
|
||||||
|
String.valueOf(threadPoolExecutor.getCompletedTaskCount()),
|
||||||
|
"已完成执行的任务总数"));
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"LargestPoolSize",
|
||||||
|
String.valueOf(threadPoolExecutor.getLargestPoolSize()),
|
||||||
|
"线程池当前状态"));
|
||||||
|
|
||||||
|
// 如果是ScheduledExecutorService,添加额外信息
|
||||||
|
if (executorService instanceof ScheduledExecutorService) {
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"线程池类型",
|
||||||
|
"ScheduledExecutorService",
|
||||||
|
"可调度的线程池"));
|
||||||
|
} else {
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"线程池类型",
|
||||||
|
"ThreadPoolExecutor",
|
||||||
|
"普通线程池"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"错误",
|
||||||
|
"未知的ExecutorService类型",
|
||||||
|
"无法获取线程池详细信息"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
executorInfoTable.getItems().add(new ExecutorInfo(
|
||||||
|
"异常",
|
||||||
|
e.getMessage(),
|
||||||
|
"获取ExecutorService信息时发生错误"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -205,7 +336,7 @@ public class TaskMonitorViewController extends BaseController {
|
|||||||
text.setFill(Color.ORANGE);
|
text.setFill(Color.ORANGE);
|
||||||
} else if (msg.getLevel() == Level.SEVERE) {
|
} else if (msg.getLevel() == Level.SEVERE) {
|
||||||
text.setFill(Color.RED);
|
text.setFill(Color.RED);
|
||||||
}else if (msg.getLevel()== Level.CONFIG) {
|
} else if (msg.getLevel() == Level.CONFIG) {
|
||||||
text.setFill(Color.GRAY);
|
text.setFill(Color.GRAY);
|
||||||
}
|
}
|
||||||
vBox.getChildren().add(text);
|
vBox.getChildren().add(text);
|
||||||
@@ -218,4 +349,11 @@ public class TaskMonitorViewController extends BaseController {
|
|||||||
alert.getDialogPane().setContent(scrollPane);
|
alert.getDialogPane().setContent(scrollPane);
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行任务监控演示
|
||||||
|
*/
|
||||||
|
public void onRunTaskMonitorDemo(ActionEvent event) {
|
||||||
|
com.ecep.contract.manager.ui.task.DemoTask.runDemo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -159,26 +159,6 @@
|
|||||||
</VBox>
|
</VBox>
|
||||||
</graphic>
|
</graphic>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- 任务监控演示 -->
|
|
||||||
<Button mnemonicParsing="false" style="-fx-padding: 6px;" onAction="#onRunTaskMonitorDemo">
|
|
||||||
<graphic>
|
|
||||||
<VBox alignment="CENTER">
|
|
||||||
<children>
|
|
||||||
<ImageView fitHeight="46.0" fitWidth="64.0">
|
|
||||||
<viewport>
|
|
||||||
<Rectangle2D height="46.0" width="64.0"/>
|
|
||||||
</viewport>
|
|
||||||
</ImageView>
|
|
||||||
<Label text="任务监控演示">
|
|
||||||
<VBox.margin>
|
|
||||||
<Insets top="5.0"/>
|
|
||||||
</VBox.margin>
|
|
||||||
</Label>
|
|
||||||
</children>
|
|
||||||
</VBox>
|
|
||||||
</graphic>
|
|
||||||
</Button>
|
|
||||||
</items>
|
</items>
|
||||||
<opaqueInsets>
|
<opaqueInsets>
|
||||||
<Insets/>
|
<Insets/>
|
||||||
|
|||||||
@@ -8,56 +8,83 @@
|
|||||||
<?import javafx.scene.control.ToolBar?>
|
<?import javafx.scene.control.ToolBar?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
<VBox minHeight="400.0" minWidth="500.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ecep.contract.manager.ui.task.TaskMonitorViewController">
|
||||||
<TabPane minHeight="400.0" minWidth="500.0" tabMinWidth="70.0" xmlns="http://javafx.com/javafx/22" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.ecep.contract.manager.ui.task.TaskMonitorViewController">
|
<ToolBar>
|
||||||
<tabs>
|
<items>
|
||||||
|
<Button fx:id="runTaskMonitorDemoBtn" text="运行演示任务" onAction="#onRunTaskMonitorDemo"/>
|
||||||
|
</items>
|
||||||
|
</ToolBar>
|
||||||
|
<TabPane tabMinWidth="70.0" VBox.vgrow="ALWAYS">
|
||||||
|
<tabs>
|
||||||
<Tab closable="false" text="活动任务">
|
<Tab closable="false" text="活动任务">
|
||||||
<content>
|
<content>
|
||||||
<VBox>
|
<VBox>
|
||||||
<children>
|
<children>
|
||||||
<ToolBar prefHeight="40.0" prefWidth="200.0">
|
<ToolBar prefHeight="40.0" prefWidth="200.0">
|
||||||
<items>
|
<items>
|
||||||
<Button fx:id="cancelTaskButton" text="取消选中任务" />
|
<Button fx:id="cancelTaskButton" text="取消选中任务"/>
|
||||||
</items>
|
</items>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
<TableView fx:id="activeTasksTable">
|
<TableView fx:id="activeTasksTable">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn fx:id="activeTaskIdColumn" prefWidth="150.0" text="任务ID" />
|
<TableColumn fx:id="activeTaskIdColumn" prefWidth="150.0" text="任务ID"/>
|
||||||
<TableColumn fx:id="activeTaskTitleColumn" prefWidth="200.0" text="任务标题" />
|
<TableColumn fx:id="activeTaskTitleColumn" prefWidth="200.0" text="任务标题"/>
|
||||||
<TableColumn fx:id="activeTaskProgressColumn" prefWidth="150.0" text="进度" />
|
<TableColumn fx:id="activeTaskProgressColumn" prefWidth="150.0" text="进度"/>
|
||||||
<TableColumn fx:id="activeTaskStatusColumn" prefWidth="100.0" text="状态" />
|
<TableColumn fx:id="activeTaskStatusColumn" prefWidth="100.0" text="状态"/>
|
||||||
</columns>
|
</columns>
|
||||||
<columnResizePolicy>
|
<columnResizePolicy>
|
||||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||||
</columnResizePolicy>
|
</columnResizePolicy>
|
||||||
</TableView>
|
</TableView>
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
</content>
|
</content>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab closable="false" text="任务历史">
|
<Tab closable="false" text="任务历史">
|
||||||
<content>
|
<content>
|
||||||
<!-- 历史任务区域 -->
|
<!-- 历史任务区域 -->
|
||||||
<VBox spacing="5.0">
|
<VBox spacing="5.0">
|
||||||
<ToolBar prefHeight="40.0" prefWidth="200.0">
|
<ToolBar prefHeight="40.0" prefWidth="200.0">
|
||||||
<items>
|
<items>
|
||||||
<Button fx:id="clearHistoryButton" alignment="CENTER_RIGHT" text="清空历史" />
|
<Button fx:id="clearHistoryButton" alignment="CENTER_RIGHT" text="清空历史"/>
|
||||||
</items>
|
</items>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
<TableView fx:id="historyTasksTable" VBox.vgrow="ALWAYS">
|
<TableView fx:id="historyTasksTable" VBox.vgrow="ALWAYS">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn fx:id="historyTaskIdColumn" prefWidth="150.0" text="任务ID" />
|
<TableColumn fx:id="historyTaskIdColumn" prefWidth="150.0" text="任务ID"/>
|
||||||
<TableColumn fx:id="historyTaskTitleColumn" prefWidth="200.0" text="任务标题" />
|
<TableColumn fx:id="historyTaskTitleColumn" prefWidth="200.0" text="任务标题"/>
|
||||||
<TableColumn fx:id="historyTaskStatusColumn" prefWidth="100.0" text="状态" />
|
<TableColumn fx:id="historyTaskStatusColumn" prefWidth="100.0" text="状态"/>
|
||||||
<TableColumn fx:id="historyTaskStartTimeColumn" prefWidth="150.0" text="开始时间" />
|
<TableColumn fx:id="historyTaskStartTimeColumn" prefWidth="150.0" text="开始时间"/>
|
||||||
<TableColumn fx:id="historyTaskExecutionTimeColumn" prefWidth="100.0" text="执行耗时" />
|
<TableColumn fx:id="historyTaskExecutionTimeColumn" prefWidth="100.0" text="执行耗时"/>
|
||||||
</columns>
|
</columns>
|
||||||
<columnResizePolicy>
|
<columnResizePolicy>
|
||||||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
|
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||||
</columnResizePolicy>
|
</columnResizePolicy>
|
||||||
</TableView>
|
</TableView>
|
||||||
</VBox>
|
</VBox>
|
||||||
</content>
|
</content>
|
||||||
</Tab>
|
</Tab>
|
||||||
</tabs>
|
<Tab closable="false" text="Executor">
|
||||||
</TabPane>
|
<content>
|
||||||
|
<VBox spacing="5.0">
|
||||||
|
<ToolBar prefHeight="40.0" prefWidth="200.0">
|
||||||
|
<items>
|
||||||
|
<Button fx:id="refreshExecutorInfoButton" text="刷新"/>
|
||||||
|
</items>
|
||||||
|
</ToolBar>
|
||||||
|
<TableView fx:id="executorInfoTable" VBox.vgrow="ALWAYS">
|
||||||
|
<columns>
|
||||||
|
<TableColumn fx:id="executorFieldColumn" prefWidth="150.0" text="字段"/>
|
||||||
|
<TableColumn fx:id="executorValueColumn" prefWidth="200.0" text="值"/>
|
||||||
|
<TableColumn fx:id="executorDescriptionColumn" prefWidth="300.0" text="描述"/>
|
||||||
|
</columns>
|
||||||
|
<columnResizePolicy>
|
||||||
|
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
|
||||||
|
</columnResizePolicy>
|
||||||
|
</TableView>
|
||||||
|
</VBox>
|
||||||
|
</content>
|
||||||
|
</Tab>
|
||||||
|
</tabs>
|
||||||
|
</TabPane>
|
||||||
|
</VBox>
|
||||||
|
|||||||
Reference in New Issue
Block a user