I am writing a Java application which runs user-submitted Java code. I run each piece of user-submitted code in its own sandbox. This sandbox involves (among other things) running each code submission in a separate process, in a separate JVM (as I understand it, there is no other way to reliably control the memory and CPU usage of the submitted code, short of bytecode-level checks/analysis).
I want each sandboxed process to have access to a certain database. The database is large (around 10 GB, could be significantly larger in the future) and user-submitted code might make many billions of more-or-less random accesses to the database. So it is important that user-submitted code be able to access the database efficiently.
This is what I think I should do: load the database into memory from the main overseer process, and then give each sandboxed process read-only access to the loaded database. How can I do this? (Again, I am working in Java.)
Or do I have the wrong idea? Should I try a different approach?