git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] ant issue #81: Fix rare ConcurrentModificationException when running with Pa...


Github user mharmer commented on the issue:

    https://github.com/apache/ant/pull/81
  
    I have a test case I wrote as well, however I was hesitant on adding it since it dealt with non-deterministic behavior of trying to reproduce the race condition. If it's desired I can add it, it's basically this:
    
    ```
        /**
         * This test ensures that when requesting Project.getCopyOfReferences a
         * ConcurrentModificationException isn't thrown.
         *
         * ExecutorService is used so Exceptions are rethrown from their executors
         * and caught by JUnit as an error.
         */
        @Test
        public void testMultithreadedGetReferences() throws Exception {
            final ExecutorService es1 = Executors.newSingleThreadExecutor();
            final Future<?> getReferencesThread = es1.submit(() -> {
                for (int i = 0; i < 1000; i++) {
                    p.getCopyOfReferences();
                }
            });
    
            final ExecutorService es2 = Executors.newSingleThreadExecutor();
            final Future<?> addReferencesThread = es2.submit(() -> {
                for (int i = 0; i < 1000; i++) {
                    p.addReference("dummy" + i, "dummyValue");
                }
            });
    
            getReferencesThread.get();
            addReferencesThread.get();
        }
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xxxxxxxxxxxxxx
For additional commands, e-mail: dev-help@xxxxxxxxxxxxxx