processorfactory.java
来自「国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB」· Java 代码 · 共 80 行
JAVA
80 行
package com.ufmobile.platform.mstreet.processor;
import java.util.Hashtable;
import java.util.ResourceBundle;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import org.hibernate.ejb.HibernatePersistence;
import com.ufmobile.platform.log.RunTimeLogger;
/**
* 处理器工厂
* com.ufmobile.platform.mstreet.processor.ProcessorFactory
* Version:Ufmobile3.0
* 2006-12-18
* Copyright 用友移动商务
*/
public class ProcessorFactory {
private static Hashtable<Integer, MOProcessor> moProcessorMap;
private static Hashtable<Integer, MTProcessor> mtProcessorMap;
private ProcessorFactory(){}
/**
* 获取ProcessInterface实例
* @param type 处理器类型@see TYPE
* @return ProcessInterface实例
*/
public synchronized static MOProcessor getMOInstance(int localId){
MOProcessor ret = null;
if(moProcessorMap == null){
moProcessorMap = new Hashtable<Integer, MOProcessor>();
}
MOProcessor moProcessor = moProcessorMap.get(new Integer(localId));
if(moProcessor == null){
moProcessor = new MOProcessor(localId);
moProcessorMap.put(new Integer(localId), moProcessor);
RunTimeLogger.info(ProcessorFactory.class, "start the id=" + localId + " MO thread");
}
ret = moProcessor;
ret.run();
return ret;
}
public synchronized static MTProcessor getMTInstance(int localId){
MTProcessor ret = null;
if(mtProcessorMap == null){
mtProcessorMap = new Hashtable<Integer, MTProcessor>();
}
MTProcessor mtProcessor = mtProcessorMap.get(new Integer(localId));
if(mtProcessor == null){
mtProcessor = new MTProcessor(localId);
mtProcessorMap.put(new Integer(localId), mtProcessor);
RunTimeLogger.info(ProcessorFactory.class, "start the id=" + localId + " MT thread");
}
ret = mtProcessor;
ret.run();
return ret;
}
static ResourceBundle getResource(){
ResourceBundle bundle = ResourceBundle.getBundle("config");
return bundle;
}
private static Hashtable<Integer, EntityManagerFactory> entityManagerFactoryMap;
static synchronized EntityManager getEntityManager(int localId){
return getEntityManager(false, localId);
}
static synchronized EntityManager getEntityManager(boolean reset, int localId){
if(entityManagerFactoryMap == null){
entityManagerFactoryMap = new Hashtable<Integer, EntityManagerFactory>();
}
EntityManagerFactory entityManagerFactory = entityManagerFactoryMap.get(new Integer(localId));
if(entityManagerFactory == null || reset){
HibernatePersistence persistence = new HibernatePersistence();
entityManagerFactory = persistence.createEntityManagerFactory("smsUnit" + localId, null);
entityManagerFactoryMap.put(new Integer(localId), entityManagerFactory);
}
return entityManagerFactory.createEntityManager();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?