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