/**
*
* Copyright (c) 1995-2009 Wonders Information Co.,Ltd.
* 1518 Lianhang Rd,Shanghai 201112.P.R.C.
* All Rights Reserved.
*
* This software is the confidential and proprietary information of Wonders Group.
* (Social Security Department). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with Wonders Group.
*
* Distributable under GNU LGPL license by gnu.org
*/ package com.yundaex.common.parent.threadpool; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Repository; /**
* <p>
* Title: Adage_[子系统统名]_[模块名]
* </p>
* <p>
* Description: 并发任务工厂,用于动态获取并发任务实例
* 注意:主要用于事务包装的并发任务,在用SPRING包装任务的事务时,需要注意,任务bean和任务代理bean必须均为Prototype类型(singleton为false)
* </p>
*
* @author Jessy
* @version $Revision$ 2010-8-4
* @author (lastest modification by $Author$)
* @since 1.0
*/
@Repository("taskFactory")
public final class TaskFactory implements ApplicationContextAware {
private ApplicationContext applicationContext; private static TaskFactory instance; private TaskFactory() { } /**
* <p>
* Discription:获取任务工厂实例
* </p>
*
* @return
*/
public static TaskFactory getInstance() {
if (instance == null) {
instance = new TaskFactory();
}
return instance;
} /**
* <p>
* Discription:创建并发任务
* </p>
*
* @param <T> 泛型
* @param type 任务类型
* @param taskClass 任务CLASS
* @return
*/
public <T extends Task> T createTask(String type, Class<T> taskClass) {
return taskClass.cast(applicationContext.getBean(type));
} /**
* {@inheritDoc}
*
* @see org.springframework.context.ApplicationContextAware#
* setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext; }
}

applicationContext-common-threadpool.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<description></description>
<bean id="simpleThreadPool" class="com.yundaex.common.parent.threadpool.runtime.SimpleThreadPool"
abstract="true">
</bean>
<bean id="dynamicThreadPool" class="com.yundaex.common.parent.threadpool.runtime.DynamicThreadPool"
abstract="true">
<!--<property name="maxSize" value="${your.module.maxSize}"></property>
<property name="minSize" value="${your.module.minSize}"></property>
<property name="checkPeriod" value="${your.module.checkPeriod}"></property>
<property name="sparePeriod" value="${your.module.sparePeriod}"></property>-->
</bean> <bean id="taskFactory" class="com.yundaex.common.parent.threadpool.TaskFactory"
factory-method="getInstance">
</bean>
</beans>

最新文章

  1. FastClick 填坑及源码解析
  2. sass编译
  3. [翻译].NET随机数
  4. Azure Backup (1) 将SQL Server 2012虚拟机中数据库备份到Azure Storage
  5. Net作业调度-----Quartz.Net
  6. PLSQL_性能优化系列15_Oracle Explain Plan解析计划解读
  7. 动手学servlet(一) 第一个servlet程序
  8. Spring基础介绍
  9. Delphi TdxBarManager通过代码生成菜单
  10. OpenStreetMap初探(一)——了解OpenStreetMap
  11. Angular JS中的路由
  12. 在XUnit中用Moq怎样模拟EntityFramework Core下的DbSet
  13. C#开发短信发送
  14. springMVC的异常处理
  15. eval和列表解析的一处陷阱
  16. Django的admin视图的使用
  17. Vue(基础七)_webpack使用工具(下)
  18. 微信小程序-图片预览
  19. java框架之SpringBoot(2)-配置
  20. XCode9和10编译Cordova报错toLowerCase of undefined解决方案

热门文章

  1. POJ 2503 Babelfish(map,字典树,快排+二分,hash)
  2. mybatis进行分页,使用limit
  3. 【Codeforces】894E.Ralph and Mushrooms Tarjan缩点+DP
  4. PS 滤镜— — 万花筒效果
  5. Spring笔记03(Spring创建对象的三种方式)
  6. 3170: [Tjoi 2013]松鼠聚会
  7. fabnacii数列
  8. SQL Replication
  9. 性能测试之Jmeter学习(十)
  10. 在Spring环境下存取properties文件…