Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Leiningen keep its own JVM running?

If I call

lein trampoline repl

Leiningen launches its own JVM process which then starts a separate JVM for the repl and quits. However calling the default

lein repl

leaves two JVMs running. Is there any reason for keeping the original Leiningen JVM process running? Why not make lein trampoline behavior the default and quit every time?

like image 690
Matthew Molloy Avatar asked Dec 07 '14 03:12

Matthew Molloy


1 Answers

lein help trampoline states:

Run a task without nesting the project's JVM inside Leiningen's.

Calculates the Clojure code to run in the project's process for the given task and allows Leiningen's own JVM process to exit before running it rather than launching a subprocess of Leiningen's JVM.

Use this to save memory or to work around stdin issues.

Arguments: ([task-name & args])

So you can see, without trampoline the second JVM runs as a sub-process of the first. That's why the first one can't exit — exiting would disrupt the second.

On the other hand, with trampoline the first JVM constructs a shell script which is then executed by the lein script to spawn the second JVM. So in this case, the second JVM is a child of the lein script. How Clojure Babies are Made: Leiningen's Trampoline covers this in quite a bit of detail.

As to why trampoline is not the default, I'm not entirely sure. But remember that not every lein command runs project code, so the second JVM is not needed for every command.

Also, there may be disadvantages to using trampoline. For example, take a look at the following lines of code from the above article:

# Just don't change :target-path in project.clj, mkay?
TRAMPOLINE_FILE="target/trampolines/$INPUT_CHECKSUM"

To me, that implies that there could be problems if :target-path is set in project.clj.

like image 196
Nathan Davis Avatar answered Oct 04 '22 16:10

Nathan Davis