是否可以预加载 JVM 以更快地启动小的一次性 Java 应用程序?

Vi.*_*Vi. 7 java jvm

预期算法:

  1. 您在没有实际应用程序的情况下启动 JVM(只告诉它加载一些 jar),它加载并侦听套接字并在后台等待。
  2. 当您启动应用程序 ( preloaded_java -cp /usr/share/java/....jar:. qqq.jar) 时,它会连接到现有加载的 JVM,加载其他 jar(如果有)并执行主类。
  3. preloaded_java 只是路由输入和输出并处理中断等。

更新实施了概念证明: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
Run Code Online (Sandbox Code Playgroud)

更新 2:自己找到答案:Nailgun 服务器(来自 VimClojure)。

Vi.*_*Vi. 3

使用钉枪服务器:

启动它:

java -classpath /usr/share/java/clojure.jar:/usr/share/java/clojure-contrib.jar com.martiansoftware.nailgun.NGServer 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

用它:

$ ng clojure.main 
Clojure 1.2.0
user=>

$ ng test.Hello sdf sdf sdf
Hello, world; number of args is 3
sdfsdf
sdfsdf
Run Code Online (Sandbox Code Playgroud)

可以使用 VimClojure 获取:http://www.vim.org/scripts/script.php ?script_id=2501