summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-09-30 17:11:24 -0700
committerJesse Wilson <jessewilson@google.com>2010-09-30 17:25:53 -0700
commitd5ef39f5d96461e5c3814157f74e30cca2234624 (patch)
tree57701790342388a4442c478d4afc814e0d4e5cbe
parente8c1e814814d5a97b0ded2de31d350928182dec5 (diff)
downloadlibcore-d5ef39f5d96461e5c3814157f74e30cca2234624.zip
libcore-d5ef39f5d96461e5c3814157f74e30cca2234624.tar.gz
libcore-d5ef39f5d96461e5c3814157f74e30cca2234624.tar.bz2
Include a message when a task is rejected from an executor.
Browser folks have been seeing this exception in their logcat logs and it would be handy to give them some insight on why the pool rejected the task. Change-Id: I7257b3b174e6e2342e63238a542095bb3f7845f2 http://b/issue?id=3023092
-rw-r--r--luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java15
-rwxr-xr-xluni/src/test/java/tests/api/java/util/concurrent/ThreadPoolExecutorTest.java29
2 files changed, 43 insertions, 1 deletions
diff --git a/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java b/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java
index 9bddc8d..7efa78b 100644
--- a/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java
+++ b/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java
@@ -1947,7 +1947,20 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
* @throws RejectedExecutionException always.
*/
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
- throw new RejectedExecutionException();
+ // BEGIN android-changed
+ // provide diagnostic messaging for a common exception
+
+ // a message is helpful even if it isn't created atomically
+ int queueSize = e.getQueue().size();
+ int remainingCapacity = e.getQueue().remainingCapacity();
+ String message = "pool=" + e.getPoolSize() + "/" + e.maximumPoolSize
+ + ", queue=" + queueSize;
+ if (remainingCapacity != Integer.MAX_VALUE) {
+ message += "/" + (queueSize + remainingCapacity);
+ }
+ throw new RejectedExecutionException(message);
+
+ // END android-changed
}
}
diff --git a/luni/src/test/java/tests/api/java/util/concurrent/ThreadPoolExecutorTest.java b/luni/src/test/java/tests/api/java/util/concurrent/ThreadPoolExecutorTest.java
index 9b7fcac..b706185 100755
--- a/luni/src/test/java/tests/api/java/util/concurrent/ThreadPoolExecutorTest.java
+++ b/luni/src/test/java/tests/api/java/util/concurrent/ThreadPoolExecutorTest.java
@@ -1479,4 +1479,33 @@ public class ThreadPoolExecutorTest extends JSR166TestCase {
}
}
+ // BEGIN android-added
+ /** http://b/3046427 */
+ public void testRejected() {
+ BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(2);
+ ExecutorService executor = new ThreadPoolExecutor(0, 2, 1, TimeUnit.SECONDS, queue);
+ executor.submit(new Sleeper()); // thread #1
+ executor.submit(new Sleeper()); // thread #2
+ executor.submit(new Sleeper()); // queue #1
+ executor.submit(new Sleeper()); // queue #2
+ try {
+ executor.submit(new Sleeper());
+ fail();
+ } catch (RejectedExecutionException expected) {
+ System.out.println(expected.getMessage());
+ assertNotNull(expected.getMessage());
+ }
+ executor.shutdown();
+ }
+
+ static class Sleeper implements Runnable {
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ // END android-added
}