0

I need to compile and execute user's code several times (business logic). Just for Hello world example compilation and execution of that code takes 2-3 seconds. Is there a way to make compiling and running java code be faster? As you can see, it is just a Hello world.

As far as code to be compiled, he will be very short (maximum number of lines should not be over 200, and within single file (with 1-2 private classes). I need to return output and the error to the user if it happens, and that's all. I use Java on Ubuntu 14.04 within Docker containers. Also, all of this is for testing programming skills. GUI is not an option, command line applications.

I'm interested in reducing time needed JVM to compile and execute that code. How I can achieve this?

Aleksandar
  • 1,163
  • 22
  • 41
  • Yes. There is. This question has nowhere near enough specifics to provide a specific answer. – Boris the Spider Aug 18 '16 at 16:38
  • @BoristheSpider You are right, I see. Just editing. – Aleksandar Aug 18 '16 at 16:41
  • For example, compiling and running [from within a live JVM](http://stackoverflow.com/a/2946402/2071828) will remove the large JVM spin-up cost, and also allow the JIT to keep its optimisations hot. If that is not an option, then the experimental [compile server](https://stackoverflow.com/questions/26424759/what-is-sjavac-who-is-it-for-and-how-do-i-use-it) will help reduce compile costs at least. – Boris the Spider Aug 18 '16 at 16:44
  • @BoristheSpider I edited question. Thanks for suggestion. – Aleksandar Aug 18 '16 at 16:48

1 Answers1

0

Assuming the code you're trying to execute is simple enough that a REPL would do, java 9 includes one, JShell. You could either just pipe input to it or use its API (jdk.jshell).

the8472
  • 40,999
  • 5
  • 70
  • 122