11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .scheduling .config ;
1818
19- import org . springframework . beans . BeanWrapper ;
20- import org . springframework . beans . BeanWrapperImpl ;
19+ import java . util . concurrent . RejectedExecutionHandler ;
20+
2121import org .springframework .beans .factory .BeanNameAware ;
2222import org .springframework .beans .factory .DisposableBean ;
2323import org .springframework .beans .factory .FactoryBean ;
2727import org .springframework .util .StringUtils ;
2828
2929/**
30- * FactoryBean for creating ThreadPoolTaskExecutor instances, choosing
31- * between the standard concurrent and the backport-concurrent variant .
30+ * {@link FactoryBean} for creating {@link ThreadPoolTaskExecutor} instances,
31+ * primarily used behind the XML task namespace .
3232 *
3333 * @author Mark Fisher
3434 * @author Juergen Hoeller
@@ -41,13 +41,13 @@ public class TaskExecutorFactoryBean implements
4141
4242 private Integer queueCapacity ;
4343
44- private Object rejectedExecutionHandler ;
44+ private RejectedExecutionHandler rejectedExecutionHandler ;
4545
4646 private Integer keepAliveSeconds ;
4747
4848 private String beanName ;
4949
50- private TaskExecutor target ;
50+ private ThreadPoolTaskExecutor target ;
5151
5252
5353 public void setPoolSize (String poolSize ) {
@@ -58,7 +58,7 @@ public void setQueueCapacity(int queueCapacity) {
5858 this .queueCapacity = queueCapacity ;
5959 }
6060
61- public void setRejectedExecutionHandler (Object rejectedExecutionHandler ) {
61+ public void setRejectedExecutionHandler (RejectedExecutionHandler rejectedExecutionHandler ) {
6262 this .rejectedExecutionHandler = rejectedExecutionHandler ;
6363 }
6464
@@ -73,28 +73,25 @@ public void setBeanName(String beanName) {
7373
7474
7575 @ Override
76- public void afterPropertiesSet () throws Exception {
77- BeanWrapper bw = new BeanWrapperImpl ( ThreadPoolTaskExecutor . class );
78- determinePoolSizeRange (bw );
76+ public void afterPropertiesSet () {
77+ this . target = new ThreadPoolTaskExecutor ( );
78+ determinePoolSizeRange ();
7979 if (this .queueCapacity != null ) {
80- bw . setPropertyValue ( "queueCapacity" , this .queueCapacity );
80+ this . target . setQueueCapacity ( this .queueCapacity );
8181 }
8282 if (this .keepAliveSeconds != null ) {
83- bw . setPropertyValue ( "keepAliveSeconds" , this .keepAliveSeconds );
83+ this . target . setKeepAliveSeconds ( this .keepAliveSeconds );
8484 }
8585 if (this .rejectedExecutionHandler != null ) {
86- bw . setPropertyValue ( "rejectedExecutionHandler" , this .rejectedExecutionHandler );
86+ this . target . setRejectedExecutionHandler ( this .rejectedExecutionHandler );
8787 }
8888 if (this .beanName != null ) {
89- bw .setPropertyValue ("threadNamePrefix" , this .beanName + "-" );
90- }
91- this .target = (TaskExecutor ) bw .getWrappedInstance ();
92- if (this .target instanceof InitializingBean ) {
93- ((InitializingBean ) this .target ).afterPropertiesSet ();
89+ this .target .setThreadNamePrefix (this .beanName + "-" );
9490 }
91+ this .target .afterPropertiesSet ();
9592 }
9693
97- private void determinePoolSizeRange (BeanWrapper bw ) {
94+ private void determinePoolSizeRange () {
9895 if (StringUtils .hasText (this .poolSize )) {
9996 try {
10097 int corePoolSize ;
@@ -108,15 +105,15 @@ private void determinePoolSizeRange(BeanWrapper bw) {
108105 "Lower bound of pool-size range must not exceed the upper bound" );
109106 }
110107 if (this .queueCapacity == null ) {
111- // no queue-capacity provided, so unbounded
108+ // No queue-capacity provided, so unbounded
112109 if (corePoolSize == 0 ) {
113- // actually set 'corePoolSize' to the upper bound of the range
114- // but allow core threads to timeout
115- bw . setPropertyValue ( "allowCoreThreadTimeOut" , true );
110+ // Actually set 'corePoolSize' to the upper bound of the range
111+ // but allow core threads to timeout...
112+ this . target . setAllowCoreThreadTimeOut ( true );
116113 corePoolSize = maxPoolSize ;
117114 }
118115 else {
119- // non -zero lower bound implies a core-max size range
116+ // Non -zero lower bound implies a core-max size range...
120117 throw new IllegalArgumentException (
121118 "A non-zero lower bound for the size range requires a queue-capacity value" );
122119 }
@@ -127,8 +124,8 @@ private void determinePoolSizeRange(BeanWrapper bw) {
127124 corePoolSize = value ;
128125 maxPoolSize = value ;
129126 }
130- bw . setPropertyValue ( "corePoolSize" , corePoolSize );
131- bw . setPropertyValue ( "maxPoolSize" , maxPoolSize );
127+ this . target . setCorePoolSize ( corePoolSize );
128+ this . target . setMaxPoolSize ( maxPoolSize );
132129 }
133130 catch (NumberFormatException ex ) {
134131 throw new IllegalArgumentException ("Invalid pool-size value [" + this .poolSize + "]: only single " +
@@ -155,10 +152,8 @@ public boolean isSingleton() {
155152
156153
157154 @ Override
158- public void destroy () throws Exception {
159- if (this .target instanceof DisposableBean ) {
160- ((DisposableBean ) this .target ).destroy ();
161- }
155+ public void destroy () {
156+ this .target .destroy ();
162157 }
163158
164159}
0 commit comments