I am writing web app for java learning. Using which users may compile their code on my serwer + run that code. Compiling is easy with JavaCompiler:
Jav
is there any way to run that code with a lifetime ?
Create a process which monitors child processes and terminates it if it takes too long.
is there any risk with memory leaks, and what can i do to fix this.
You should be able to do that, to some extent, by controlling how much memory is allocated (like the -Xmx
parameter to Sun's JVM).
is this good solution, or can you suggest something better ?
I'm not sure a solution has been proposed, but here's a thought. Install a SecurityManager that greatly restricts what the executed code can do, such as access the filesystem, spawn processes, etc. Combine that with a process that monitors for timeouts, limits the allocated memory, runs the application under a separate user account, etc., and I think you can have something workable.
What you're looking for is possible, but may not be entirely so if your restricted to only Java.