garydgregory commented on code in PR #367:
URL: https://github.com/apache/commons-vfs/pull/367#discussion_r1070092163


##########
commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/VfsClassLoaderTests.java:
##########
@@ -203,6 +214,84 @@ public void testSealing() throws Exception {
         verifyPackage(pack, true);
     }
 
+    @Test
+    public void testThreadSafety() throws Exception {
+        final int THREADS = 20;
+        BlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<>(THREADS * 
2);
+        List<Throwable> exceptions = new ArrayList<>();
+        Thread.UncaughtExceptionHandler handler = new 
Thread.UncaughtExceptionHandler() {
+            @Override
+            public void uncaughtException(Thread t, Throwable e) {
+                synchronized(exceptions) {
+                    exceptions.add(e);
+                }
+            }
+        };
+        ThreadFactory factory = new 
ThreadFactoryBuilder().setUncaughtExceptionHandler(handler).build();
+        Queue<Runnable> rejections = new LinkedList<>();
+        RejectedExecutionHandler rejectionHandler = new 
RejectedExecutionHandler() {
+            @Override
+            public void rejectedExecution(Runnable r, ThreadPoolExecutor 
executor) {
+                synchronized(rejections) {
+                    rejections.add(r);
+                }
+            }
+        };
+        ThreadPoolExecutor executor = new ThreadPoolExecutor(THREADS, THREADS, 
0, TimeUnit.SECONDS, workQueue, factory, rejectionHandler);
+        executor.prestartAllCoreThreads();
+        for (int i = 0; i < THREADS; i++) {
+            VFSClassLoader loader = createClassLoader();
+            workQueue.put(new VfsClassLoaderTests.LoadClass(loader));
+        }
+        while (!workQueue.isEmpty()) {
+            Thread.sleep(10);
+        }
+        while (!rejections.isEmpty() && executor.getActiveCount() > 0) {
+            List<Runnable> rejected = new ArrayList<>();
+            synchronized(rejections) {
+                rejected.addAll(rejections);
+                rejections.clear();
+            }
+            workQueue.addAll(rejected);
+        }
+        executor.shutdown();
+        executor.awaitTermination(30, TimeUnit.SECONDS);
+        assertEquals(THREADS, executor.getCompletedTaskCount());
+        if (!exceptions.isEmpty()) {
+            for (Throwable t : exceptions) {
+                System.out.println(t.toString());

Review Comment:
   No console output, please.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to