/**
*
* 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. 常见排序算法-php

    1.归并排序 $a = [1, 4, 6, 8, 10, 14, 16]; $b = [2, 3, 5, 8, 9, 11]; function merge_sort($a, $b) { $a_i = ...

  2. linux命令学习笔记(46):vmstat命令

    vmstat是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动 进行监控.他是对系统的整体情况进行统计,不足之处是无法对某个进程进行 ...

  3. POI2014

    ...一个shabi和一堆神题的故事 今天只写了两道 之后随缘更吧 啊 顺便 snake我是不会更的 bzoj3829 POI2014 Farmcraft mhy住在一棵有n个点的树的1号结点上,每个 ...

  4. linux历史及基本知识

    1. Linux的历史: 1973年,Ken Thompson以C语言写出第一个正式版的UNIX内核, 1977年:重要的UNIX分支——BSD(Berkeley Sofeware Distribut ...

  5. ASP.Net MVC实现一个表单多个submit

    1. 用Html.BeginForm(ActionName,ControllerName,Post)来实现controller-action的路由, 2. Form里的每个input的name值统一, ...

  6. docker基于宿主机系统版本创建镜像

    这里讲如何定制自己centos镜像,仅供测试docker使用. A) 安装软件 yum -y install febootstrap B)下载镜像febootstrap -i bash -i wget ...

  7. MySQL 之 扩展例子

    扩展例子 插入一条记录 INSERT INTO 表名 [(字段1,…,字段n)] VALUES (值1,…,值n) 插入查询的结果 INSERT INTO 表名 (字段1,…,字段n) VALUES ...

  8. 2019计蒜之道初赛4 B. 腾讯益智小游戏—矩形面积交(简单)(矩形交集)

    B. 腾讯益智小游戏—矩形面积交(简单) 1000ms 262144K   腾讯游戏开发了一款全新的编程类益智小游戏,最新推出的一个小游戏题目是关于矩形面积交的.聪明的你能解出来吗?看下面的题目接招吧 ...

  9. cassandra的命令

    cassandra的命令: connect <hostname>/<port> (<username> '<password>')?;    Conne ...

  10. 数据库路由中间件MyCat - 源代码篇(13)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 4.配置模块 4.2 schema.xml 接上一篇,接下来载入每个schema的配置(也就是每个MyCat ...