[英]Store process object in database
I am doing 我在做
Process p = null;
if(CheckOS.isWindows())
p = rt.exec(filebase+port+"/hlds.exe +maxplayers "+players+ " -game cstrike -console +port "+port+" -nojoy -noipx -heapsize 250000 +map de_dust2 +servercfgfile server.cfg +lservercfgfile +mapcyclefile mapcycle.txt +motdfile motd.txt +logsdir logs -zone 2048",null, new File(filebase+port)) ;
and want to store p
in database but process is not serializable, how to save it in database?? 并想将p
存储在数据库中,但进程不可序列化,如何将其保存在数据库中?
and can we check if process p
is still running or died due to some crash or something 我们可以检查进程p
是否由于某些崩溃或其他原因而仍在运行或死亡
You definitely cannot store a Process itself in a database. 您绝对不能将流程本身存储在数据库中。 But if you are trying to keep processes around for future use (within the scope of the VM), then you can have something like this: 但是,如果您尝试保留进程以备将来使用(在VM的范围内),那么您可以拥有以下内容:
public class ProcessRegistry {
public static class Key {}
private static final ProcessRegistry INSTANCE = new ProcessRegistry();
public static ProcessRegistry getInstance() { return INSTANCE; }
private final Map<Object, Process> _processes = new HashMap<...>();
public Key registry(Process p) {
Key key = new Object();
_processes.put(key, p);
return key;
}
public Process lookup(Key key) {
return _processes.get(key);
}
}
You can store and lookup from wherever (within the confines of your classloader) using 您可以从任何地方(在类加载器的范围内)使用以下命令存储和查找
ProcessRegistry.getInstance().register(...)
etc. 等等
There is no easy way to save a process to a database. 没有简单的方法可以将进程保存到数据库。 Instead you can save a reference to it in the database. 相反,您可以在数据库中保存对其的引用。 If I was doing it I would do: 如果我这样做,我会这样做:
When looking it up you can look up the process with an id to see if it has ended. 查找时,您可以查找带有ID的进程以查看其是否结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.