JDK-8144799 : Executors.newSingleThreadExecutor().submit(runnable) throw RejectedExeception
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 8u66,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_suse_sles_11
  • CPU: x86_64
  • Submitted: 2015-11-24
  • Updated: 2015-12-16
  • Resolved: 2015-12-16
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode) 

A DESCRIPTION OF THE PROBLEM :
When spring framework init a bean object, it will invoke afterPropertiesSet() method.
My code like this:
public void afterPropertiesSet()
	{
		Executors.newSingleThreadExecutor().submit(new Runnable()
		{
			@Override
			public void run()
			{
				Thread.currentThread().setName("StartUp-1");
				try
				{
				   .....
				}
				catch (Exception e)
				{
					logger.error("", e);
				}
			}
			
		});
	}
but there throw a RejectedExeception:
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@694abf75 rejected from java.util.concurrent.ThreadPoolExecutor@15e7578d[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
	at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369)
	at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
	at java.util.concurrent.Executors$DelegatedExecutorService.submit(Executors.java:678)
	at demo.MyService.afterPropertiesSet(TopoService.java:248)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
	... 18 more


REPRODUCIBILITY :
This bug can be reproduced rarely.


Comments
With heroic efforts, it's probably possible to teach ThreadPoolExecutor to be happy with zero core threads, and then after a keepalive period the last thread will exit and the pool can be collected and we won't need the finalizable delegate
16-12-2015

Received additional inputs from submitter in the new bug JDK-8145304. The issue will be tracked with the new bug now, closing this as duplicate.
16-12-2015

Closing this as incomplete for now ( as per submitter's response , issue occurred once with JDK 6 . It didn't occur with JDK 7) Will Reopen in case get some more inputs on reproducing the issue.
07-12-2015