com.fastchar.extjs.systemtool.entity.FinalLogThreadEntity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastchar-extjs-systemtool Show documentation
Show all versions of fastchar-extjs-systemtool Show documentation
FastChar-ExtJs-SystemTool is a FastChar-ExtJs plugin.
The newest version!
package com.fastchar.extjs.systemtool.entity;
import com.fastchar.core.FastChar;
import com.fastchar.extjs.core.FastExtEntity;
import com.fastchar.database.FastPage;
import com.fastchar.database.info.FastSqlInfo;
import com.fastchar.utils.FastDateUtils;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.*;
import java.util.concurrent.locks.LockSupport;
import com.fastchar.utils.FastStringUtils;
/**
* 系统线程运行记录数据库实体类
*
* @author Janesen
* @date 2024/03/25 10:59
*/
public class FinalLogThreadEntity extends FastExtEntity {
private static final long serialVersionUID = 1L;
public static FinalLogThreadEntity dao() {
return FastChar.getOverrides().singleInstance(FinalLogThreadEntity.class);
}
public static FinalLogThreadEntity newInstance() {
return FastChar.getOverrides().newInstance(FinalLogThreadEntity.class);
}
@Override
public String getTableName() {
return "final_log_thread";
}
@Override
public String getTableDetails() {
return "系统线程运行记录";
}
@Override
public String getEntityCode() {
return this.getClass().getSimpleName();
}
@Override
public FastPage showList(int page, int pageSize) {
String sqlStr = "select t.*" +
" from final_log_thread as t" +
" ";
FastSqlInfo sqlInfo = toSelectSql(sqlStr);
return selectBySql(page, pageSize, sqlInfo.getSql(), sqlInfo.toParams());
}
@Override
public void setDefaultValue() {
set("threadElapsed", 0);
set("logDateTime", FastDateUtils.getDateString());
}
@Override
public void convertValue() {
super.convertValue();
}
@Override
public boolean save(String...checks) {
return super.save(checks);
}
@Override
public boolean update(String...checks){
return super.update(checks);
}
public enum ThreadStateEnum{
NEW,
RUNNABLE,
BLOCKED,
WAITING,
TIMED_WAITING,
TERMINATED;
}
public void refreshData() {
String clearSqlStr = "delete from final_log_thread ";
this.updateBySql(clearSqlStr);
try {
List list = new ArrayList<>();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
int index = 1;
ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
for (ThreadInfo threadInfo : threadInfos) {
long elapsedTime = threadMXBean.getThreadCpuTime(threadInfo.getThreadId());
FinalLogThreadEntity logThreadEntity = FinalLogThreadEntity.newInstance();
logThreadEntity.set("logId", index++);
logThreadEntity.set("logDateTime", FastDateUtils.getDateString());
logThreadEntity.set("threadName", threadInfo.getThreadName());
logThreadEntity.set("threadId", threadInfo.getThreadId());
logThreadEntity.set("threadState", threadInfo.getThreadState().name());
logThreadEntity.set("threadElapsed", elapsedTime / 1_000_000_000.0);
List stackTraces = new ArrayList<>();
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
stackTraces.add(stackTraceElement.toString());
}
logThreadEntity.set("threadStack", FastStringUtils.join(stackTraces, "\n\t"));
list.add(logThreadEntity);
}
FastChar.getDB().batchSaveEntity(list, list.size());
} catch (Exception e) {
FastChar.getLogger().error(this.getClass(), e);
}
}
/**
* 获得数据详情
*/
public FinalLogThreadEntity getDetails(String logId) {
List linkColumns = new ArrayList<>();
linkColumns.add("t.*");
String sqlStr = "select " + FastStringUtils.join(linkColumns, ",") + " from final_log_thread as t" + " "
+ " where t.logId = ? ";
FinalLogThreadEntity entity = selectFirstBySql(sqlStr, logId);
if (entity != null) {
// to-do something
}
return entity;
}
/**
* 获得本实体列表集合
*
* @return 分页数据
*/
public FastPage getList(int page, int pageSize, Map where,
Map sort) {
List linkColumns = new ArrayList<>();
linkColumns.add("t.*");
StringBuilder sqlStr = new StringBuilder("select " + FastStringUtils.join(linkColumns, ",")
+ " from final_log_thread as t" + " " + " where 1=1 ");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy