You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2018/01/23 13:58:14 UTC
[sling-org-apache-sling-commons-threads] branch master updated:
SLING-7432 - Thread pool clean up code can lead to infinite loops in
ThreadLocal.get
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-threads.git
The following commit(s) were added to refs/heads/master by this push:
new 21a553d SLING-7432 - Thread pool clean up code can lead to infinite loops in ThreadLocal.get
21a553d is described below
commit 21a553d7bcc4f090097d878461308974e189a6c3
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Jan 23 15:25:47 2018 +0200
SLING-7432 - Thread pool clean up code can lead to infinite loops in
ThreadLocal.get
Added failing test, ignored for now
---
...ThreadPoolExecutorCleaningThreadLocalsTest.java | 45 +++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/src/test/java/org/apache/sling/commons/threads/impl/ThreadPoolExecutorCleaningThreadLocalsTest.java b/src/test/java/org/apache/sling/commons/threads/impl/ThreadPoolExecutorCleaningThreadLocalsTest.java
index 413ab57..7e6b92a 100644
--- a/src/test/java/org/apache/sling/commons/threads/impl/ThreadPoolExecutorCleaningThreadLocalsTest.java
+++ b/src/test/java/org/apache/sling/commons/threads/impl/ThreadPoolExecutorCleaningThreadLocalsTest.java
@@ -16,17 +16,21 @@
*/
package org.apache.sling.commons.threads.impl;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionHandler;
-import java.util.concurrent.ThreadPoolExecutor;
+ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.sling.commons.threads.impl.ThreadLocalChangeListener.Mode;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
@@ -51,6 +55,20 @@ public class ThreadPoolExecutorCleaningThreadLocalsTest {
1, 1, 100, TimeUnit.MILLISECONDS,
queue, Executors.defaultThreadFactory(), rejectionHandler, listener);
}
+
+ @Test(timeout = 10000)
+ @Ignore
+ public void threadLocalCleanupWorksWithResize() throws Exception {
+
+ // configure thread local counts to make sure that
+ // 1. the ThreadLocalMap is initialized with the default size
+ // 2. the ThreadLocalMap size is expanded
+ int[] tlcount = new int[] { 16, 32 };
+ for (int count : tlcount) {
+ Future<?> result = pool.submit(new RunnableImplementation(count));
+ result.get();
+ }
+ }
@Test
public void testThreadLocalBeingCleanedUp() throws InterruptedException, ExecutionException {
@@ -68,6 +86,31 @@ public class ThreadPoolExecutorCleaningThreadLocalsTest {
Assert.assertNull(task.getOldValue());
}
+ private static class RunnableImplementation implements Runnable {
+ private final int threadLocalCount;
+ private final List<ThreadLocal<String>> threadLocals = new ArrayList<>();
+
+
+ public RunnableImplementation(int threadLocalCount) {
+ this.threadLocalCount = threadLocalCount;
+ }
+
+ @Override
+ public void run() {
+ for ( int i = 0 ; i < threadLocalCount; i++) {
+ ThreadLocal<String> tl = new ThreadLocal<>();
+ tl.set("val");
+
+ threadLocals.add(tl);
+ }
+
+ for ( ThreadLocal<String> tl : threadLocals ) {
+ String val = tl.get();
+ val.toString();
+ }
+ }
+ }
+
private static class ThreadLocalTask implements Runnable {
static final ThreadLocal<String> threadLocalVariable = new ThreadLocal<String>();
--
To stop receiving notification emails like this one, please contact
rombert@apache.org.