⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtprocessor.java

📁 国内很牛的软件公司花费两年半开发的用EJB3开发的代码,采用STRUTS和EJB3,目前系统进行第二版.所以拿出来共享
💻 JAVA
字号:
package com.ufmobile.platform.mstreet.processor;

import java.math.BigDecimal;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.ufmobile.platform.InitListener;
import com.ufmobile.platform.ejb.EJBBoClient;
import com.ufmobile.platform.log.RunTimeLogger;
import com.ufmobile.platform.mstreet.sms.ISMSSender;
import com.ufmobile.platform.mstreet.sms.MTSubmit;

public class MTProcessor{
	
	static int max_thread_count = 10;
	static final String TABLE_NAME = "TB_SMS_MTSUBMIT";
	static final String COLUMN_PK_NAME    = "ID";
	static final String COLUMN_DONEFLAG = "DONEFLAG";
	static final String MT_MAX_THREAD_COUNT = "MT_MAX_THREAD_COUNT";
	public static final int DONEFLAG_FLAG_ERROR = -1;
	public static final int DONEFLAG_FLAG_OK = 1;
	public static final int UNDONEFLAG_FLAG = 0;

	private ProcessorPool pool;
	private long minID;
	private int localId;
//	private int count = 0;
//	synchronized public void addCount(int increment){
//		count += increment;
//	}
//	synchronized protected void minusCount(){
//		if(count > 0){
//			count--;
//		}		
//	}
//	public int getCount(){
//		return count;
//	}
	
	MTProcessor(int localId){
		this.localId = localId;
		try{
			String s = ProcessorFactory.getResource().getString(MT_MAX_THREAD_COUNT);		
			if(s != null && s.compareTo("") != 0){
				max_thread_count = Integer.parseInt(s);
			}
		}
		catch(Exception e){
			RunTimeLogger.error(this, "get MO_MAX_THREAD_COUNT from config.properties ", e);
			e.printStackTrace();
		}
	}
	
	void run() {
		if(pool == null){
			pool = new ProcessorPool(localId, this, max_thread_count);
			pool.start();
		}
//		else{
//			pool.activeByHand();
//		}
	}
	
	synchronized long getMinID(int localId) {
		this.minID = 0;
		Query query = ProcessorFactory.getEntityManager(localId).createNativeQuery(" select min("+ COLUMN_PK_NAME +") from " + TABLE_NAME + 
				" where "+ COLUMN_DONEFLAG +" = ?1");
		query.setParameter(1, UNDONEFLAG_FLAG);
		List<BigDecimal> bigDecimalList = query.getResultList();
		if(bigDecimalList != null && bigDecimalList.size() > 0){
			if(bigDecimalList.get(0) != null){
				this.minID = bigDecimalList.get(0).longValue();
			}
		}		
		return this.minID;
	}
	
	static boolean process(MTProcessor mtProcessor, long id, int localId) {
		boolean ret = true;
		EntityManager manager = ProcessorFactory.getEntityManager(localId);
		Query query = manager.createQuery(" from MTSubmit a where a.id = ?1");
		query.setParameter(1, new Long(id).intValue());
		RunTimeLogger.info(MTProcessor.class, "select MTSubmit where id="+ id);
		List<MTSubmit> list = query.getResultList();
		MTSubmit info = null;
		if(list != null && list.size() > 0){
			info = list.get(0);
		}
		if(info != null){			
			if(info.getDoneflag() == UNDONEFLAG_FLAG){
				int result = 0;
				try{
					ISMSSender bean = (ISMSSender)EJBBoClient.getRemoteClient(InitListener.CENTER_ID, "ISMSSenderBean");
					result = bean.MtSubmit(new MTSubmit[]{info});										
				}		
				catch(Exception e){
					result = 0;
					RunTimeLogger.error(MTProcessor.class, "处理MT", e);
				}
				manager.getTransaction().begin();
				query = manager.createNativeQuery(" update TB_SMS_MTSUBMIT set doneflag = :FLAG where id = :ID");
				query.setParameter("ID", id);
				if(result == 1){				
					query.setParameter("FLAG", DONEFLAG_FLAG_OK);
				}
				else{				
					query.setParameter("FLAG", DONEFLAG_FLAG_ERROR);
				}			
				query.executeUpdate();
				manager.getTransaction().commit();
//				finally{
//					mtProcessor.minusCount();
//				}	
			}
								
		}
		else{
			ret = false;
		}
		return ret;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -