@ -16,11 +16,10 @@
@@ -16,11 +16,10 @@
package org.springframework.scheduling.config ;
import java.util.concurrent.ThreadPoolExecutor ;
import org.w3c.dom.Element ;
import org.springframework.beans.factory.support.BeanDefinitionBuilder ;
import org.springframework.beans.factory.support.RootBeanDefinition ;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser ;
import org.springframework.beans.factory.xml.ParserContext ;
import org.springframework.core.JdkVersion ;
@ -28,18 +27,21 @@ import org.springframework.util.StringUtils;
@@ -28,18 +27,21 @@ import org.springframework.util.StringUtils;
/ * *
* Parser for the ' executor ' element of the ' task ' namespace .
*
*
* @author Mark Fisher
* @author Juergen Hoeller
* @since 3 . 0
* /
public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
@Override
protected String getBeanClassName ( Element element ) {
if ( this . shouldUseBackport ( element ) ) {
if ( shouldUseBackport ( element ) ) {
return "org.springframework.scheduling.backportconcurrent.ThreadPoolTaskExecutor" ;
}
return "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" ;
else {
return "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" ;
}
}
@Override
@ -52,7 +54,7 @@ public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
@@ -52,7 +54,7 @@ public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
if ( StringUtils . hasText ( queueCapacity ) ) {
builder . addPropertyValue ( "queueCapacity" , queueCapacity ) ;
}
this . configureRejectionPolicy ( element , builder ) ;
configureRejectionPolicy ( element , builder ) ;
String poolSize = element . getAttribute ( "pool-size" ) ;
if ( ! StringUtils . hasText ( poolSize ) ) {
return ;
@ -104,43 +106,33 @@ public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
@@ -104,43 +106,33 @@ public class ExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionPa
if ( ! StringUtils . hasText ( rejectionPolicy ) ) {
return ;
}
Object handler = null ;
boolean createBackportHandler = this . shouldUseBackport ( element ) ;
String prefix = "java.util.concurrent.ThreadPoolExecutor." ;
if ( builder . getRawBeanDefinition ( ) . getBeanClassName ( ) . contains ( "backport" ) ) {
prefix = "edu.emory.mathcs.backport." + prefix ;
}
String policyClassName ;
if ( rejectionPolicy . equals ( "ABORT" ) ) {
if ( createBackportHandler ) {
handler = new edu . emory . mathcs . backport . java . util . concurrent . ThreadPoolExecutor . AbortPolicy ( ) ;
}
else {
handler = new ThreadPoolExecutor . AbortPolicy ( ) ;
}
policyClassName = prefix + "AbortPolicy" ;
}
if ( rejectionPolicy . equals ( "CALLER_RUNS" ) ) {
if ( createBackportHandler ) {
handler = new edu . emory . mathcs . backport . java . util . concurrent . ThreadPoolExecutor . CallerRunsPolicy ( ) ;
}
else {
handler = new ThreadPoolExecutor . CallerRunsPolicy ( ) ;
}
else if ( rejectionPolicy . equals ( "CALLER_RUNS" ) ) {
policyClassName = prefix + "CallerRunsPolicy" ;
}
if ( rejectionPolicy . equals ( "DISCARD" ) ) {
if ( createBackportHandler ) {
handler = new edu . emory . mathcs . backport . java . util . concurrent . ThreadPoolExecutor . DiscardPolicy ( ) ;
}
handler = new ThreadPoolExecutor . DiscardPolicy ( ) ;
else if ( rejectionPolicy . equals ( "DISCARD" ) ) {
policyClassName = prefix + "DiscardPolicy" ;
}
if ( rejectionPolicy . equals ( "DISCARD_OLDEST" ) ) {
if ( createBackportHandler ) {
handler = new edu . emory . mathcs . backport . java . util . concurrent . ThreadPoolExecutor . DiscardOldestPolicy ( ) ;
}
handler = new ThreadPoolExecutor . DiscardOldestPolicy ( ) ;
else if ( rejectionPolicy . equals ( "DISCARD_OLDEST" ) ) {
policyClassName = prefix + "DiscardOldestPolicy" ;
}
else {
policyClassName = rejectionPolicy ;
}
builder . addPropertyValue ( "rejectedExecutionHandler" , handler ) ;
builder . addPropertyValue ( "rejectedExecutionHandler" , new RootBeanDefinition ( policyClassName ) ) ;
}
private boolean shouldUseBackport ( Element element ) {
String poolSize = element . getAttribute ( "pool-size" ) ;
return StringUtils . hasText ( poolSize ) & & poolSize . startsWith ( "0" )
& & JdkVersion . getMajorJavaVersion ( ) < JdkVersion . JAVA_16 ;
return ( StringUtils . hasText ( poolSize ) & & poolSize . startsWith ( "0" ) & &
JdkVersion . getMajorJavaVersion ( ) < JdkVersion . JAVA_16 ) ;
}
}