introduced ForkJoinPoolFactoryBean for Java 7 (alternative: add new jsr166.jar to Java 6)

This commit is contained in:
Juergen Hoeller 2011-08-15 16:41:55 +00:00
parent aa46d18125
commit 4acb0fa284
4 changed files with 132 additions and 11 deletions

View File

@ -30,6 +30,7 @@
<classpathentry kind="var" path="IVY_CACHE/org.aspectj/com.springsource.org.aspectj.weaver/1.6.8.RELEASE/com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.beanshell/com.springsource.bsh/2.0.0.b4/com.springsource.bsh-2.0.0.b4.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.6.5/com.springsource.org.codehaus.groovy-1.6.5.jar" sourcepath="/IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.6.5/com.springsource.org.codehaus.groovy-sources-1.6.5.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.jsr166-mirror/com.springsource.jsr166/1.7.0/com.springsource.jsr166-1.7.0.jar" sourcepath="/IVY_CACHE/org.codehaus.jsr166-mirror/com.springsource.jsr166/1.7.0/com.springsource.jsr166-sources-1.7.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.hamcrest/com.springsource.org.hamcrest/1.1.0/com.springsource.org.hamcrest-1.1.0.jar" sourcepath="/IVY_CACHE/org.hamcrest/1.1.0/com.springsource.org.hamcrest-1.1.0.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-2.5.1.jar" sourcepath="/IVY_CACHE/org.easymock/com.springsource.org.easymock/2.5.1/com.springsource.org.easymock-sources-2.5.1.jar"/>
<classpathentry kind="var" path="IVY_CACHE/org.joda/com.springsource.org.joda.time/1.6.0/com.springsource.org.joda.time-1.6.0.jar" sourcepath="/IVY_CACHE/org.joda/com.springsource.org.joda.time/1.6.0/com.springsource.org.joda.time-sources-1.6.0.jar"/>

View File

@ -102,6 +102,28 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.codehaus.jsr166-mirror/com.springsource.jsr166/1.7.0/com.springsource.jsr166-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$IVY_CACHE$/org.codehaus.jsr166-mirror/com.springsource.jsr166/1.7.0/com.springsource.jsr166-sources-1.7.0.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/net.sourceforge.ehcache/com.springsource.net.sf.ehcache/1.6.2/com.springsource.net.sf.ehcache-1.6.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$IVY_CACHE$/net.sourceforge.ehcache/com.springsource.net.sf.ehcache/1.6.2/com.springsource.net.sf.ehcache-sources-1.6.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
@ -155,17 +177,6 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/net.sourceforge.ehcache/com.springsource.net.sf.ehcache/1.6.2/com.springsource.net.sf.ehcache-1.6.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$IVY_CACHE$/net.sourceforge.ehcache/com.springsource.net.sf.ehcache/1.6.2/com.springsource.net.sf.ehcache-sources-1.6.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
</component>
<component name="copyright">
<Base>

View File

@ -50,6 +50,7 @@
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="${aspectj.version}" conf="optional, aspectj->compile"/>
<dependency org="org.beanshell" name="com.springsource.bsh" rev="2.0.0.b4" conf="optional, beanshell->compile"/>
<dependency org="org.codehaus.groovy" name="com.springsource.org.codehaus.groovy" rev="1.6.5" conf="optional, groovy->compile"/>
<dependency org="org.codehaus.jsr166-mirror" name="com.springsource.jsr166" rev="1.7.0" conf="provided->compile"/>
<dependency org="org.hibernate" name="com.springsource.org.hibernate.validator" rev="4.1.0.GA" conf="optional->compile"/>
<dependency org="org.joda" name="com.springsource.org.joda.time" rev="1.6.0" conf="optional->compile"/>
<dependency org="org.jruby" name="com.springsource.org.jruby" rev="1.4.0" conf="optional, jruby->compile"/>

View File

@ -0,0 +1,108 @@
/*
* Copyright 2002-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.scheduling.concurrent;
import java.util.concurrent.ForkJoinPool;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
/**
* A Spring {@link FactoryBean} that builds and exposes a preconfigured {@link ForkJoinPool}.
* May be used on Java 7 as well as on Java 6 with <code>jsr166.jar</code> on the classpath
* (ideally on the VM bootstrap classpath).
*
* <p>For details on the ForkJoinPool API and its its use with RecursiveActions, see the
* <a href="http://download.java.net/jdk7/docs/api/java/util/concurrent/ForkJoinPool.html">JDK 7 javadoc</a>.
*
* <p><code>jsr166.jar</code>, containing <code>java.util.concurrent</code> updates for Java 6, can be obtained
* from the <a href="http://gee.cs.oswego.edu/dl/concurrency-interest/">concurrency interest website</a>.
*
* @author Juergen Hoeller
* @since 3.1
*/
public class ForkJoinPoolFactoryBean implements FactoryBean<ForkJoinPool>, InitializingBean, DisposableBean {
private int parallelism = Runtime.getRuntime().availableProcessors();
private ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = ForkJoinPool.defaultForkJoinWorkerThreadFactory;
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
private boolean asyncMode = false;
private ForkJoinPool forkJoinPool;
/**
* Specify the parallelism level. Default is {@link Runtime#availableProcessors()}.
*/
public void setParallelism(int parallelism) {
this.parallelism = parallelism;
}
/**
* Set the factory for creating new ForkJoinWorkerThreads.
* Default is {@link ForkJoinPool#defaultForkJoinWorkerThreadFactory}.
*/
public void setThreadFactory(ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory) {
this.threadFactory = threadFactory;
}
/**
* Set the handler for internal worker threads that terminate due to unrecoverable errors
* encountered while executing tasks. Default is none.
*/
public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
this.uncaughtExceptionHandler = uncaughtExceptionHandler;
}
/**
* Specify whether to establish a local first-in-first-out scheduling mode for forked tasks
* that are never joined. This mode (asyncMode = <code>true</code>) may be more appropriate
* than the default locally stack-based mode in applications in which worker threads only
* process event-style asynchronous tasks. Default is <code>false</code>.
*/
public void setAsyncMode(boolean asyncMode) {
this.asyncMode = asyncMode;
}
public void afterPropertiesSet() {
this.forkJoinPool =
new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode);
}
public ForkJoinPool getObject() {
return this.forkJoinPool;
}
public Class<?> getObjectType() {
return ForkJoinPool.class;
}
public boolean isSingleton() {
return true;
}
public void destroy() {
this.forkJoinPool.shutdown();
}
}