Skip to content

Commit ded013b

Browse files
author
magiclu550
committed
[commit] you can close something by jar args
1 parent 89e2f0f commit ded013b

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

.idea/artifacts/jsmod2.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cn.jsmod2;
2+
3+
import cn.jsmod2.core.Server;
4+
import cn.jsmod2.core.utils.Utils;
5+
6+
public class JVMRuntime {
7+
8+
private Runtime runtime = Runtime.getRuntime();
9+
10+
private Server server;
11+
12+
public JVMRuntime(Server server){
13+
this.server = server;
14+
}
15+
16+
public void setServerArgs(){
17+
try {
18+
String heap = server.serverProp.getProperty(Register.MAX_HEAP, "1024");
19+
server.getLogger().multiInfo(getClass(),"Set the JVM max_heap to "+heap+" m","","");
20+
//java -Xmx1024m 最大堆 以及自定义jvm命令
21+
runtime.exec("java -Xmx" + heap + "m "+server.serverProp.getProperty(Register.JVM_ARGS));
22+
}catch (Exception e){
23+
Utils.printException(e);
24+
}
25+
}
26+
}

JPLS/src/main/java/cn/jsmod2/Register.java

+7
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ public void registerPacket(){
187187

188188
public static final String START_NETTY_SERVER = "client.server.start";
189189

190+
public static final String MAX_HEAP = "jsmod2.jvm.max.heap";
191+
192+
public static final String JVM_ARGS = "jsmod2.jvm.args";
193+
194+
190195
@RegisterMethod
191196
public void registerSuccessInfo(){
192197
successInfo.add("start.finish");
@@ -201,6 +206,8 @@ public void registerServerProperties(){
201206
serverProperties.put(CONSOLE_LOG,"");
202207
serverProperties.put(START_NETTY_SERVER,"true");
203208
serverProperties.put(CLIENT_PORT,"20020");
209+
serverProperties.put(MAX_HEAP,"1024");
210+
serverProperties.put(JVM_ARGS,"");
204211
}
205212

206213

JPLS/src/main/java/cn/jsmod2/ServerStarter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@
1212
import static cn.jsmod2.core.utils.Utils.contains;
1313

1414
/**
15-
* -w -u -lr -lm -github
15+
* -w -u -lr -lm -github -a
1616
* -w 关闭web
1717
* -u 关闭ui
1818
* -lr 关闭round的log监听
1919
* -lm 关闭multiAdmin和游戏的log监听
2020
* -github 关闭和Github连接
21+
* -a 关闭全部
2122
*/
2223
@ServerApplication(DefaultServer.class)
2324
public class ServerStarter {
2425

2526
public void start(String[] args){
27+
if(contains(args,"-a")){
28+
args[0] = "-w-u-lr-l-github";
29+
}
2630
Utils.TryCatch(()->{
2731
CountDownLatch latch = new CountDownLatch(1);
2832
if(!contains(args,"-w")) {

JPLS/src/main/java/cn/jsmod2/core/Server.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package cn.jsmod2.core;
1010

1111

12+
import cn.jsmod2.JVMRuntime;
1213
import cn.jsmod2.Register;
1314
import cn.jsmod2.core.annotations.RegisterMethod;
1415
import cn.jsmod2.core.command.OpsFile;
@@ -149,6 +150,8 @@ public Server(GameServer gServer,boolean useUDP) {
149150

150151
this.serverProp = getFileSystem().serverProperties(server);
151152

153+
JVMRuntime runtime = new JVMRuntime(this);
154+
runtime.setServerArgs();
152155

153156
getLogger().multiInfo(getClass(),"Connecting the multiAdmin | LocalAdmin","","");
154157

@@ -201,7 +204,6 @@ public void start(Class<?> main,String[] args) {
201204

202205
public void startWatch(Class<?> main,String[] args) {
203206
Utils.TryCatch(()-> {
204-
this.log.multiInfo(this.getClass(),main.getSimpleName() + "::start::" + main.getName(),"","");
205207
this.executeEmerald(args, true);
206208
this.start(args);
207209
this.successTime();
@@ -232,9 +234,7 @@ public void start(String[] args){
232234
this.pool.execute(new GithubConnectThread());
233235
}
234236
}
235-
//this.pool.execute(new ServerThread());
236237

237-
//this.pool.execute(new Smod2LogThread());
238238
this.startSuccessTime = new Date().getTime();
239239
}
240240

0 commit comments

Comments
 (0)