You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 of java, as expected, the program keeps running even after main finishes.
Start Client (in parallel, just after having started Server): 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 the exec plugin, the server keeps running as expected. Same if I use exec: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.
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.
The text was updated successfully, but these errors were encountered: