Open oliviercailloux opened 3 months ago
There is a response on SO ... should we fix some of documentation ...?
PR are welcome
I may have missed something but it seems to me that the response proposed on SO is a workaround. It does not tackle the discrepancy between the doc and the observed behavior of the exec goal.
To make it perhaps clearer: my bug report is about the java goal not quitting once all known non daemon threads have quit. The doc states that it should.
The
org.codehaus.mojo:exec-maven-plugin:3.3.0
plugin “java” goal documentation states that “daemon threads are joined and interrupted once all known non daemon threads have quit”. That is not what I observe with some code involving an RMI thread (except that I do not know what is an “unknown” thread). It looks like either a bug or a problem in the documentation.Details
My “Server” program starts a non-daemon thread (through RMI) and when I run it using the “java” goal, the JVM exits when reaching the end of the
main
method. I’d expect that it keeps running due to the non daemon thread still running. When I run it using direct invocation ofjava
, as expected, the program keeps running even aftermain
finishes.Code
Here is the Server.
Here is the Client.
The full code is here.
Reproduce the problem
git clone https://github.com/oliviercailloux/JGradLib-Additioner.git ; cd JGradLib-Additioner ; git checkout rmistop
mvn -Dexec.mainClass=io.github.oliviercailloux.javagrade.graders.Server compile org.codehaus.mojo:exec-maven-plugin:3.3.0:java
.java -cp "target/classes/" io.github.oliviercailloux.javagrade.graders.User
.Expected: The RMI mechanism starts a non-daemon thread in the background and prevents exit of the JVM, so that the Server stays alive indefinitely and the Client prints forever the result of the
test
call.Actual: the Server starts, RMI starts a non-daemon thread as expected (as well as daemon threads), the Server sleeps for three seconds, prints its threads, and exits. The Client, meanwhile, starts flooding the terminal with results of the
test
calls, but after three seconds, crashes with a stack trace complaining that it cannot reach the remote end any more.Variants with no problem
Both the
exec
plugin and the RMI aspect seem required to trigger this odd behavior.If running the server with
java -cp "target/classes/" io.github.oliviercailloux.javagrade.graders.Server
instead of theexec
plugin, the server keeps running as expected. Same if I useexec:java
(with appropriate options).Alternatively, if I change the server code to simply start a new Thread that is kept busy (sleeps in a while loop), the server keeps running as expected.
Also posted on SO.