Pankraz76 commented on code in PR #2382: URL: https://github.com/apache/maven/pull/2382#discussion_r2103993970
########## its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java: ########## @@ -70,86 +71,97 @@ public class CheckThreadSafetyMojo extends AbstractMojo { * Runs this mojo. * * @throws MojoExecutionException If the output file could not be created. + * + * @implNote threads need to use different realms to trigger changes of the collections. */ public void execute() throws MojoExecutionException { - Properties componentProperties = new Properties(); - getLog().info("[MAVEN-CORE-IT-LOG] Testing concurrent component access"); - - ClassLoader pluginRealm = getClass().getClassLoader(); - ClassLoader coreRealm = MojoExecutionException.class.getClassLoader(); - - final Map map = componentMap; - final List list = componentList; - final List go = new Vector(); - final List exceptions = new Vector(); - - Thread[] threads = new Thread[2]; + final List<Exception> exceptions = new Vector<>(); + final CountDownLatch startLatch = new CountDownLatch(1); + final Thread[] threads = new Thread[2]; for (int i = 0; i < threads.length; i++) { - // NOTE: The threads need to use different realms to trigger changes of the collections - final ClassLoader cl = (i % 2) == 0 ? pluginRealm : coreRealm; - threads[i] = new Thread() { - private final ClassLoader tccl = cl; - - public void run() { - getLog().info("[MAVEN-CORE-IT-LOG] Thread " + this + " uses " + tccl); - Thread.currentThread().setContextClassLoader(tccl); - while (go.isEmpty()) { - // wait for start - } - for (int j = 0; j < 10 * 1000; j++) { - try { - for (Object o : map.values()) { - o.toString(); - } - for (Object aList : list) { - aList.toString(); - } - } catch (Exception e) { - getLog().warn("[MAVEN-CORE-IT-LOG] Thread " + this + " encountered concurrency issue", e); - exceptions.add(e); - } - } - } - }; + threads[i] = new CheckThreadSafetyThread((i % 2) == 0 ? Review Comment: ```suggestion threads[i] = new CheckThreadSafetyThread((i % 2) == (0) ? ``` why there is no [UnnecessaryParentheses](https://checkstyle.sourceforge.io/checks/coding/unnecessaryparentheses.html) on 0? now I see, where the problem at. Thanks check. ########## its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java: ########## @@ -70,86 +71,97 @@ public class CheckThreadSafetyMojo extends AbstractMojo { * Runs this mojo. * * @throws MojoExecutionException If the output file could not be created. + * + * @implNote threads need to use different realms to trigger changes of the collections. */ public void execute() throws MojoExecutionException { - Properties componentProperties = new Properties(); - getLog().info("[MAVEN-CORE-IT-LOG] Testing concurrent component access"); - - ClassLoader pluginRealm = getClass().getClassLoader(); - ClassLoader coreRealm = MojoExecutionException.class.getClassLoader(); - - final Map map = componentMap; - final List list = componentList; - final List go = new Vector(); - final List exceptions = new Vector(); - - Thread[] threads = new Thread[2]; + final List<Exception> exceptions = new Vector<>(); + final CountDownLatch startLatch = new CountDownLatch(1); + final Thread[] threads = new Thread[2]; for (int i = 0; i < threads.length; i++) { - // NOTE: The threads need to use different realms to trigger changes of the collections - final ClassLoader cl = (i % 2) == 0 ? pluginRealm : coreRealm; - threads[i] = new Thread() { - private final ClassLoader tccl = cl; - - public void run() { - getLog().info("[MAVEN-CORE-IT-LOG] Thread " + this + " uses " + tccl); Review Comment: this comes from the logger normally, right? its kind of dry: <img width="400" alt="image" src="https://github.com/user-attachments/assets/745ee741-b950-4368-a9bd-1de65b2b31a7" /> ########## its/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java: ########## @@ -70,86 +71,97 @@ public class CheckThreadSafetyMojo extends AbstractMojo { * Runs this mojo. * * @throws MojoExecutionException If the output file could not be created. + * + * @implNote threads need to use different realms to trigger changes of the collections. */ public void execute() throws MojoExecutionException { - Properties componentProperties = new Properties(); - getLog().info("[MAVEN-CORE-IT-LOG] Testing concurrent component access"); - - ClassLoader pluginRealm = getClass().getClassLoader(); - ClassLoader coreRealm = MojoExecutionException.class.getClassLoader(); - - final Map map = componentMap; - final List list = componentList; - final List go = new Vector(); - final List exceptions = new Vector(); - - Thread[] threads = new Thread[2]; + final List<Exception> exceptions = new Vector<>(); + final CountDownLatch startLatch = new CountDownLatch(1); + final Thread[] threads = new Thread[2]; for (int i = 0; i < threads.length; i++) { - // NOTE: The threads need to use different realms to trigger changes of the collections Review Comment: might be candidate for @implNote to give special attention, thus higher scope. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org