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 dat开发者_StackOverflow社区abase but process is not serializable, how to save it in database??
and can we check if process p
is still running or died due to some crash or something
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:
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:
- Create a new process
- Save the process to a map with some id
- Save that id to database
When looking it up you can look up the process with an id to see if it has ended.
精彩评论