/**
*
* 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>

TaskFactory单例模式利用xml的更多相关文章

  1. C# 解析html —— 将html转为XHTML,然后利用Xml解析

    呵呵,由于正则不熟,所以另谋出路——利用XML去解析html. 要想将抓取到的数据(直接抓取到的是byte[])  转为XML文档(即XMLDocument对象),有两个要点: 一.判断编码(http ...

  2. 教你如何利用xml格式的sitemap文件做好SEO

    教你如何利用xml格式的sitemap文件做好SEO 浏览: | 更新:-- : 一般的网站中都有网站地图文件,它有HTML格式与XML格式,网站地图可以帮助搜索引擎抓取.帮助用户找到自己所需要的内容 ...

  3. C#配合利用XML文件构建反射表机制

    在设计程序时,无论是界面或是后台代码,我们通常都想留给用户一个较为简单的接口.而我在参与封装语音卡开发函数包的时候,发现各种语音卡的底层函数的接口都是各种整形变量标记值,使用起来极为不变.于是就理解了 ...

  4. ajax技术实现登录判断用户名是否重复以及利用xml实现二级下拉框联动,还有从数据库中获得

    今天学了ajax技术,特地在此写下来作为复习. 一.什么是ajax? 客户端(特指PC浏览器)与服务器,可以在[不必刷新整个浏览器]的情况下,与服务器进行异步通讯的技术  即,AJAX是一个[局部刷新 ...

  5. spring利用xml配置定时任务

    在开发中会经常遇到做定时任务的需求,例如日志定时清理与处理,数据信息定时同步等需求. 1.在spring中利用xml配置定时任务,如下 <!-- ftpiptv信息同步接口定时任务配置--> ...

  6. 利用XML FOR PATH 合并分组信息

    -- ================================================ -- Description:合并分组内容 -- Author:夏保华 -- Date:2009 ...

  7. java分享第十八天-02( java结合testng,利用XML做数据源的数据驱动)

    testng的功能很强大,利用@DataProvider可以做数据驱动,数据源文件可以是EXCEL,XML,YAML,甚至可以是TXT文本.在这以XML为例:备注:@DataProvider的返回值类 ...

  8. java结合testng,利用XML做数据源的数据驱动示例

    testng的功能很强大,利用@DataProvider可以做数据驱动,数据源文件可以是EXCEL,XML,YAML,甚至可以是TXT文本.在这以XML为例: 备注:@DataProvider的返回值 ...

  9. 利用XML序列化和Asp.Net Web缓存实现站点配置文件

    我们经常会遇到这样的场景: 今天来了个业务,需要加一个字段,但是考虑的以后可能有变动,需要配成“活”的. 一般最初的做法就是加一个配置到Web.Config文件的AppSettings中去.但是这样有 ...

随机推荐

  1. frame标签

    frame中有一个属性scrolling,可以这样设置它 <frame src="top.html" noresize scrolling="no"/&g ...

  2. python学习笔记:第五天( 字典)

    Python3 字典 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包括在花括号({})中 ,格 ...

  3. Linux下查找进程,kill进程

    1. ps命令用来查找linux运行的进程,常用命令: ps aux | grep 进程名:  eg:ps aux | grep admin 查找admin的进程 或者 ps -ef | grep j ...

  4. What can I yield?

    浏览器支持情况:Enabled by default in desktop Chrome 39  一句话回答这个问题是:Promise,Thunks.为什么没有Generators?因为Generat ...

  5. codeforces 610D D. Vika and Segments(离散化+线段树+扫描线算法)

    题目链接: D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  6. leetcode 111 Minimum Depth of Binary Tree(DFS)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  7. Python: scikit-image Blob detection

    这个用例主要介绍利用三种算法对含有blob的图像进行检测,blob 或者叫斑点,就是在一幅图像上,暗背景上的亮区域,或者亮背景上的暗区域,都可以称为blob.主要利用blob与背景之间的对比度来进行检 ...

  8. CardView以及RecycleView的一些问题

    下面这些属性在listview的标签里有用,在recyclerView里没用. tools:listitem="@layout/list_single_answer_item_borrowe ...

  9. configured to save RDB snapshots, but is currently not able to persist o...

    Redis问题 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on d ...

  10. this在方法赋值过程中无法保持(隐式丢失)

    在看<高级程序设计>(我的红宝书) P.183页时遇到下面一个问题 var name = "77"; var obj = { name: "88", ...