7
1
Expected algorithm:
- You start JVM without actual application (only telling it to load some jars), it loads and listens a socket and waits in a background.
- 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. 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).
A quick perusal does not reveal any class loader tricks, so a class will only be initialized once per server run, and not "per use". This may or may not have an effect on the correctness of whatever you are running under NailGun. – Ken – 2010-09-18T00:48:12.333
If some code fails on NailGun because of this then it is probably not well-written. In a good program "initialized once per server run" should just mean that it would be even more fast. – Vi. – 2010-09-18T17:26:35.333