7

Expected algorithm:

  1. You start JVM without actual application (only telling it to load some jars), it loads and listens a socket and waits in a background.
  2. When you start the application (preloaded_java -cp /usr/share/java/....jar:. qqq.jar) it connects to the existing loaded JVM, loads additional jars (if any) and executes main class.
  3. preloaded_java just routes input and output and handles interrupts etc.

Update Implemented a proof of concept: http://vi-server.org/vi/code/prejvm/

$ clojure prejvm.clj&
[1] 2883
$ nc 127.0.0.1 7711 <<< '{"mainclass" "test.Hello"}'
$ nc 127.0.0.1 7712
java.lang.ClassNotFoundException: test.Hello
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    ...
    at clojure.main.main(main.java:37)

$ nc 127.0.0.1 7711 <<< '{"classpaths" ["file:///home/vi/code/prejvm/"], "mainclass" "test.Hello"}'    
$ nc 127.0.0.1 7712
Hello, world; number of args is 0
qwe q e32e qda
qwe q e32e qda

$ nc 127.0.0.1 7711 <<< '{"classpaths" ["file:///home/vi/code/prejvm/"], "mainclass" "test.Hello", "argv" ["qqq" "www" "eee"]}'
$ nc 127.0.0.1 7712    
Hello, world; number of args is 3
sdfasdfasf df sad
sdfasdfasf df sad

Update 2: Found answer myself: Nailgun server (from VimClojure).

gronostaj
  • 58,482
Vi.
  • 17,755

3 Answers3

3

Use Nailgun Server:

Start it:

java -classpath /usr/share/java/clojure.jar:/usr/share/java/clojure-contrib.jar com.martiansoftware.nailgun.NGServer 127.0.0.1

Use it:

$ ng clojure.main 
Clojure 1.2.0
user=>

$ ng test.Hello sdf sdf sdf
Hello, world; number of args is 3
sdfsdf
sdfsdf

It can be obtained with VimClojure: http://www.vim.org/scripts/script.php?script_id=2501

Vi.
  • 17,755
0

No, what you describe is not possible, at least not with the Sun JVM, simply because it's not implemented (though it's a nice idea).

However, if you just run the app once, the OS will cache the data in RAM that was loaded from disk, so subsequent starts should be a lot faster. That might already help.

If you need a higher speedup: Can you maybe change the app, such that it just keeps running and accepts new input?

sleske
  • 23,525
0

Sure it can be done. What you describe is actually pretty close to how a Java EE application server works.

jlliagre
  • 14,369