Skip to content

Commit 03b87b5

Browse files
Copilotslachiewicz
andauthored
Document thread group isolation limitation in java goal (#503)
* Document thread group isolation limitation in java goal Add detailed documentation explaining that the java goal only tracks threads in its isolated thread group, which causes it to exit early when frameworks like RMI create non-daemon threads in other thread groups. This clarifies the behavior reported in the issue where RMI servers exit prematurely when using exec:java, and provides clear guidance to use exec:exec as a workaround. Co-authored-by: slachiewicz <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: slachiewicz <[email protected]>
1 parent 7a66c3e commit 03b87b5

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/site/apt/usage.apt.vm

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,43 @@ mvn exec:exec -Dexec.executable="maven" [-Dexec.workingdir="/tmp"] -Dexec.args="
9393
*--------------------------------------+------------------------------------------+
9494
| The VM exits as soon as the only | By default daemon threads are joined |
9595
| remaining threads are daemon threads | and interrupted once all known non |
96-
| | daemon threads have quit. The join |
97-
| | timeout is customisable |
98-
| | The user might wish to further |
96+
| | daemon threads have quit. The join |
97+
| | timeout is customisable. |
98+
| | The user might wish to further |
9999
| | cleanup by stopping the unresponsive |
100100
| | threads. |
101101
| | The user can disable the full extra |
102102
| | thread management (interrupt/join/[stop])|
103103
*--------------------------------------+------------------------------------------+
104104

105+
*** Important limitation: Thread Group Isolation
106+
107+
The java goal tracks threads created within its own <<isolated thread group>>.
108+
It does <<not>> track threads created in other thread groups.
109+
This means that if your code creates threads outside the isolated thread group
110+
(for example, through RMI, JMX, or other frameworks), those threads will not be
111+
detected as "known" threads, and the plugin may exit even if such non-daemon threads are still running.
112+
113+
<<Examples of affected scenarios:>>
114+
115+
* <<RMI>> - <<<java.rmi.registry.LocateRegistry.createRegistry()>>> creates non-daemon threads
116+
in the system thread group, not in the plugin's isolated thread group.
117+
118+
* <<JMX>> - Similar to RMI, JMX remote connectors may create threads outside the isolated group.
119+
120+
* <<Other frameworks>> that manage their own thread pools or create threads using
121+
the system thread group.
122+
123+
[]
124+
125+
In such cases, the plugin will exit when all threads in <<its own thread group>> have completed,
126+
even though non-daemon threads may still be running in other thread groups. This can cause
127+
servers or services to be terminated prematurely.
128+
129+
<<Workaround:>> If you need threads created by frameworks like RMI to keep the JVM alive,
130+
use the {{{./exec-mojo.html}exec goal}} to run your Java program in a separate JVM process instead.
131+
The exec goal spawns a new process which will behave like running <<<java>>> from the command line.
132+
105133
Read the documentation for the {{{./java-mojo.html}java goal}} for more information on how to configure this behavior.
106134

107135
If you find out that these differences are unacceptable for your case, you may need to use the {{{./exec-mojo.html} exec goal}} to wrap your Java executable.

0 commit comments

Comments
 (0)