mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-29 18:38:32 +08:00
读写锁调整
This commit is contained in:
parent
4b3b0ba2a5
commit
042bdf0f20
@ -41,7 +41,7 @@ import java.util.jar.Manifest;
|
||||
*/
|
||||
public abstract class AbstractProjectCommander {
|
||||
|
||||
public static final String RUNING_TAG = "running";
|
||||
public static final String RUNNING_TAG = "running";
|
||||
public static final String STOP_TAG = "stopped";
|
||||
|
||||
private static AbstractProjectCommander abstractProjectCommander = null;
|
||||
@ -242,7 +242,7 @@ public abstract class AbstractProjectCommander {
|
||||
if (virtualMachine == null) {
|
||||
return AbstractProjectCommander.STOP_TAG;
|
||||
}
|
||||
return StrUtil.format("{}:{}", AbstractProjectCommander.RUNING_TAG, virtualMachine.id());
|
||||
return StrUtil.format("{}:{}", AbstractProjectCommander.RUNNING_TAG, virtualMachine.id());
|
||||
}
|
||||
|
||||
//---------------------------------------------------- 基本操作----end
|
||||
@ -371,7 +371,7 @@ public abstract class AbstractProjectCommander {
|
||||
* @return int
|
||||
*/
|
||||
protected static int parsePid(String result) {
|
||||
if (result.startsWith(AbstractProjectCommander.RUNING_TAG)) {
|
||||
if (result.startsWith(AbstractProjectCommander.RUNNING_TAG)) {
|
||||
return Convert.toInt(result.split(":")[1]);
|
||||
}
|
||||
return 0;
|
||||
@ -386,7 +386,7 @@ public abstract class AbstractProjectCommander {
|
||||
*/
|
||||
public boolean isRun(String tag) throws Exception {
|
||||
String result = status(tag);
|
||||
return result.contains(AbstractProjectCommander.RUNING_TAG);
|
||||
return result.contains(AbstractProjectCommander.RUNNING_TAG);
|
||||
}
|
||||
|
||||
/***
|
||||
|
@ -107,7 +107,7 @@ public class AgentWebSocketConsoleHandle extends BaseAgentWebSocketHandle {
|
||||
case restart:
|
||||
logUser = true;
|
||||
strResult = consoleService.execCommand(consoleCommandOp, projectInfoModel);
|
||||
if (strResult.contains(AbstractProjectCommander.RUNING_TAG)) {
|
||||
if (strResult.contains(AbstractProjectCommander.RUNNING_TAG)) {
|
||||
resultData = JsonMessage.toJson(200, "操作成功:" + strResult);
|
||||
} else {
|
||||
resultData = JsonMessage.toJson(400, strResult);
|
||||
@ -126,7 +126,7 @@ public class AgentWebSocketConsoleHandle extends BaseAgentWebSocketHandle {
|
||||
case status:
|
||||
// 获取项目状态
|
||||
strResult = consoleService.execCommand(consoleCommandOp, projectInfoModel);
|
||||
if (strResult.contains(AbstractProjectCommander.RUNING_TAG)) {
|
||||
if (strResult.contains(AbstractProjectCommander.RUNNING_TAG)) {
|
||||
resultData = JsonMessage.toJson(200, "运行中", strResult);
|
||||
} else {
|
||||
resultData = JsonMessage.toJson(404, "未运行", strResult);
|
||||
|
@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
/**
|
||||
* json 文件读写工具
|
||||
@ -17,6 +18,9 @@ import java.io.FileNotFoundException;
|
||||
* @date 2017/5/15
|
||||
*/
|
||||
public class JsonFileUtil {
|
||||
private static final ReentrantReadWriteLock FILE_LOCK = new ReentrantReadWriteLock();
|
||||
private final static ReentrantReadWriteLock.ReadLock READ_LOCK = FILE_LOCK.readLock();
|
||||
private final static ReentrantReadWriteLock.WriteLock WRITE_LOCK = FILE_LOCK.writeLock();
|
||||
|
||||
/**
|
||||
* 读取json 文件,同步
|
||||
@ -25,18 +29,21 @@ public class JsonFileUtil {
|
||||
* @return JSON
|
||||
* @throws FileNotFoundException 文件异常
|
||||
*/
|
||||
public static Object readJson(String path) throws FileNotFoundException {
|
||||
public static JSON readJson(String path) throws FileNotFoundException {
|
||||
File file = new File(path);
|
||||
if (!file.exists()) {
|
||||
throw new FileNotFoundException("没有找到对应配置文件:" + path);
|
||||
}
|
||||
READ_LOCK.lock();
|
||||
// 防止多线程操作文件异常
|
||||
synchronized (JsonFileUtil.class) {
|
||||
try {
|
||||
String json = FileUtil.readString(file, CharsetUtil.UTF_8);
|
||||
if (StrUtil.isEmpty(json)) {
|
||||
return JSONObject.parseObject("{}");
|
||||
return new JSONObject();
|
||||
}
|
||||
return JSON.parse(json);
|
||||
return (JSON) JSON.parse(json);
|
||||
} finally {
|
||||
READ_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,11 +54,14 @@ public class JsonFileUtil {
|
||||
* @param json 新的json内容
|
||||
*/
|
||||
public static void saveJson(String path, JSON json) {
|
||||
WRITE_LOCK.lock();
|
||||
// 防止多线程操作文件异常
|
||||
synchronized (JsonFileUtil.class) {
|
||||
try {
|
||||
// 输出格式化后的json 字符串
|
||||
String newsJson = JSON.toJSONString(json, true);
|
||||
FileUtil.writeString(newsJson, path, CharsetUtil.UTF_8);
|
||||
} finally {
|
||||
WRITE_LOCK.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
17
modules/common/src/test/java/cn/jiangzeyin.java
Normal file
17
modules/common/src/test/java/cn/jiangzeyin.java
Normal file
@ -0,0 +1,17 @@
|
||||
package cn;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class jiangzeyin {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Properties properties = System.getProperties();
|
||||
for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) {
|
||||
Map.Entry entry = (Map.Entry) objectObjectEntry;
|
||||
System.out.print(entry.getKey() + "=");
|
||||
System.out.println(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
@ -65,7 +65,6 @@
|
||||
}
|
||||
|
||||
function tabChange(options) {
|
||||
console.log(options)
|
||||
var element = top.layui.element;
|
||||
var lay_id = 'tab_' + options.id;
|
||||
if (options.id != "welcome") {
|
||||
|
@ -22,7 +22,7 @@
|
||||
}
|
||||
|
||||
.ztree {
|
||||
height: 80vh;
|
||||
min-height: 80vh;
|
||||
overflow-x: scroll;
|
||||
padding: 10px;
|
||||
}
|
||||
@ -87,7 +87,7 @@
|
||||
};
|
||||
|
||||
var curenntNode = {
|
||||
filename: "跟路径",
|
||||
filename: '根路径',
|
||||
index: -1,
|
||||
isDirectory: true
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user