1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .scheduling .config ;
18
18
19
- import org . springframework . beans . BeanWrapper ;
20
- import org . springframework . beans . BeanWrapperImpl ;
19
+ import java . util . concurrent . RejectedExecutionHandler ;
20
+
21
21
import org .springframework .beans .factory .BeanNameAware ;
22
22
import org .springframework .beans .factory .DisposableBean ;
23
23
import org .springframework .beans .factory .FactoryBean ;
27
27
import org .springframework .util .StringUtils ;
28
28
29
29
/**
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 .
32
32
*
33
33
* @author Mark Fisher
34
34
* @author Juergen Hoeller
@@ -41,13 +41,13 @@ public class TaskExecutorFactoryBean implements
41
41
42
42
private Integer queueCapacity ;
43
43
44
- private Object rejectedExecutionHandler ;
44
+ private RejectedExecutionHandler rejectedExecutionHandler ;
45
45
46
46
private Integer keepAliveSeconds ;
47
47
48
48
private String beanName ;
49
49
50
- private TaskExecutor target ;
50
+ private ThreadPoolTaskExecutor target ;
51
51
52
52
53
53
public void setPoolSize (String poolSize ) {
@@ -58,7 +58,7 @@ public void setQueueCapacity(int queueCapacity) {
58
58
this .queueCapacity = queueCapacity ;
59
59
}
60
60
61
- public void setRejectedExecutionHandler (Object rejectedExecutionHandler ) {
61
+ public void setRejectedExecutionHandler (RejectedExecutionHandler rejectedExecutionHandler ) {
62
62
this .rejectedExecutionHandler = rejectedExecutionHandler ;
63
63
}
64
64
@@ -73,28 +73,25 @@ public void setBeanName(String beanName) {
73
73
74
74
75
75
@ 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 ();
79
79
if (this .queueCapacity != null ) {
80
- bw . setPropertyValue ( "queueCapacity" , this .queueCapacity );
80
+ this . target . setQueueCapacity ( this .queueCapacity );
81
81
}
82
82
if (this .keepAliveSeconds != null ) {
83
- bw . setPropertyValue ( "keepAliveSeconds" , this .keepAliveSeconds );
83
+ this . target . setKeepAliveSeconds ( this .keepAliveSeconds );
84
84
}
85
85
if (this .rejectedExecutionHandler != null ) {
86
- bw . setPropertyValue ( "rejectedExecutionHandler" , this .rejectedExecutionHandler );
86
+ this . target . setRejectedExecutionHandler ( this .rejectedExecutionHandler );
87
87
}
88
88
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 + "-" );
94
90
}
91
+ this .target .afterPropertiesSet ();
95
92
}
96
93
97
- private void determinePoolSizeRange (BeanWrapper bw ) {
94
+ private void determinePoolSizeRange () {
98
95
if (StringUtils .hasText (this .poolSize )) {
99
96
try {
100
97
int corePoolSize ;
@@ -108,15 +105,15 @@ private void determinePoolSizeRange(BeanWrapper bw) {
108
105
"Lower bound of pool-size range must not exceed the upper bound" );
109
106
}
110
107
if (this .queueCapacity == null ) {
111
- // no queue-capacity provided, so unbounded
108
+ // No queue-capacity provided, so unbounded
112
109
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 );
116
113
corePoolSize = maxPoolSize ;
117
114
}
118
115
else {
119
- // non -zero lower bound implies a core-max size range
116
+ // Non -zero lower bound implies a core-max size range...
120
117
throw new IllegalArgumentException (
121
118
"A non-zero lower bound for the size range requires a queue-capacity value" );
122
119
}
@@ -127,8 +124,8 @@ private void determinePoolSizeRange(BeanWrapper bw) {
127
124
corePoolSize = value ;
128
125
maxPoolSize = value ;
129
126
}
130
- bw . setPropertyValue ( "corePoolSize" , corePoolSize );
131
- bw . setPropertyValue ( "maxPoolSize" , maxPoolSize );
127
+ this . target . setCorePoolSize ( corePoolSize );
128
+ this . target . setMaxPoolSize ( maxPoolSize );
132
129
}
133
130
catch (NumberFormatException ex ) {
134
131
throw new IllegalArgumentException ("Invalid pool-size value [" + this .poolSize + "]: only single " +
@@ -155,10 +152,8 @@ public boolean isSingleton() {
155
152
156
153
157
154
@ 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 ();
162
157
}
163
158
164
159
}
0 commit comments