package com.poson.aspz; import java.io.File; import java.rmi.RemoteException; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import org.apache.log4j.Logger; import com.poson.aspz.db.TranContext; import com.poson.aspz.util.Config; import com.poson.aspz.util.Const; import com.poson.aspz.util.MyLoger; import com.poson.aspz.util.Util; import java.net.MalformedURLException; import ws.clinet.axis2.WebSoapBindingImplServiceCallbackHandler; import ws.clinet.axis2.WebSoapBindingImplServiceStub; import java.sql.Connection; import java.sql.DriverManager; public class OnTimeCreditIntf extends Thread { private boolean bSuperUser = false; private boolean working = false; private String planXMLFileFN = ""; private String path = ""; private String staffNo = ""; private String pswd = ""; private String staffId = ""; private String siteId = ""; private String areaId = ""; private TranContext myDBTrans = null; private String curCreatePZDate = ""; protected Connection conn; //private static Log log = LogFactory.getLog(Worker.class); //private static MyLoger log = new MyLoger(); private Logger logger = Logger.getLogger(OnTimeCreditIntf.class); public OnTimeCreditIntf() { } public Connection getConnection() { try { conn = DriverManager.getConnection(Const.CONFIG_XML_DB_URL); return conn; } catch (Exception ex) { ex.printStackTrace(); return null; } } /** * 建立连接 * @param driver * @param url * @param user * @param password * @return */ public Connection getConnection(String driver, String url, String user, String password) { try { Class.forName(driver); conn = DriverManager.getConnection(url, user, password); return conn; } catch (Exception ex) { ex.printStackTrace(); return null; } } public List getBJOnTimeCreditIntfSumbit() throws SQLException { ArrayList list = new ArrayList(); ResultSet rs = null; StringBuffer strSql = new StringBuffer(); strSql.append(" SELECT TRIM(ORDER_SERIAL_NBR) ORDER_SERIAL_NBR, "); strSql.append(" TRIM(OWE_BUSINESS_TYPE_ID) OWE_BUSINESS_TYPE_ID,TRIM(STAFF_ID) STAFF_ID, "); strSql.append(" TRIM(SERV_ID) SERV_ID,TO_CHAR(CREATED_DATE, 'yyyymmddhhmmss') CREATED_DATE,TO_CHAR(COMPLETED_DATE, 'yyyymmddhhmmss') COMPLETED_DATE, "); strSql.append(" TRIM(STATE) STATE,TO_CHAR(STATE_DATE, 'yyyymmddhhmmss') STATE_DATE,TRIM(PROCESS_COUNT) PROCESS_COUNT, "); strSql.append(" TRIM(PRE_SERV_STATE) PRE_SERV_STATE,TRIM(REMARK) REMARK,TRIM(CHARGE) CHARGE,TRIM(BALANCE) BALANCE, "); strSql.append(" TRIM(CREDIT) CREDIT,TRIM(OWE_TASK_ITEM_ID) OWE_TASK_ITEM_ID "); strSql.append(" FROM A_WORK_ORDER "); strSql.append(" WHERE STATE='P0C' AND ROWNUM<500 ORDER BY ORDER_SERIAL_NBR "); rs = myDBTrans.executeQuery(strSql.toString()); while (rs.next()) { HashMap planInfo = new HashMap(); planInfo.put("ORDER_SERIAL_NBR",rs.getString("ORDER_SERIAL_NBR")); planInfo.put("OWE_BUSINESS_TYPE_ID",rs.getString("OWE_BUSINESS_TYPE_ID")); planInfo.put("STAFF_ID",rs.getString("STAFF_ID")); planInfo.put("SERV_ID",rs.getString("SERV_ID")); planInfo.put("CREATED_DATE",rs.getString("CREATED_DATE")); planInfo.put("COMPLETED_DATE",rs.getString("COMPLETED_DATE")); planInfo.put("STATE",rs.getString("STATE")); planInfo.put("STATE_DATE",rs.getString("STATE_DATE")); planInfo.put("PROCESS_COUNT",rs.getString("PROCESS_COUNT")); planInfo.put("PRE_SERV_STATE",rs.getString("PRE_SERV_STATE")); planInfo.put("REMARK",rs.getString("REMARK")); planInfo.put("CHARGE",rs.getString("CHARGE")); planInfo.put("BALANCE",rs.getString("BALANCE")); planInfo.put("CREDIT",rs.getString("CREDIT")); planInfo.put("OWE_TASK_ITEM_ID",rs.getString("OWE_TASK_ITEM_ID")); list.add(planInfo); } if (rs != null) { rs.close(); rs = null; } return list; } // public void updateBJOnTimeCreditIntfPlan(String requestId,String serial) throws SQLException // { // ResultSet rs = null; // StringBuffer strSql = new StringBuffer(); // strSql.append(" UPDATE A_WORK_ORDER SET STATE='P0P',REMARK='处理成功',SERIAL='" + serial + "'"); // strSql.append(" WHERE ORDER_SERIAL_NBR= " + requestId); // rs = myDBTrans.executeQuery(strSql.toString()); // } public void deleteBJOnTimeCreditIntfPlan(String requestId) throws SQLException { StringBuffer strSql = new StringBuffer(); strSql.append(" DELETE FROM A_WORK_ORDER "); strSql.append(" WHERE ORDER_SERIAL_NBR= " + requestId); myDBTrans.doBatch(strSql.toString()); } public void insertBJOnTimeAWorkOrderLog(String requestId,String serial) throws SQLException { StringBuffer strSql = new StringBuffer(); strSql.append(" INSERT INTO A_WORK_ORDER_LOG (order_serial_nbr,owe_business_type_id,staff_id, "); strSql.append(" serv_id,created_date,completed_date,state,state_date,process_count,pre_serv_state,remark,"); strSql.append(" tran_manual_date,hd_staff_id,charge,balance,credit,owe_task_item_id,SERIAL) "); strSql.append(" select order_serial_nbr,owe_business_type_id,staff_id, " ); strSql.append(" serv_id,created_date,completed_date,'P0P',sysdate,process_count,pre_serv_state,remark,"); strSql.append(" null,null,charge,balance,credit,owe_task_item_id,'" +serial + "' from A_WORK_ORDER "); strSql.append(" WHERE ORDER_SERIAL_NBR= " + requestId); myDBTrans.doBatch(strSql.toString()); } public void updateBJOnTimeCreditFailPlan(String requestId,String error, String serial) throws SQLException { StringBuffer strSql = new StringBuffer(); strSql.append(" UPDATE A_WORK_ORDER SET STATE='P0E',state_date=sysdate,REMARK='" + error + "',SERIAL='" + serial + "'"); strSql.append(" WHERE ORDER_SERIAL_NBR= " + requestId); myDBTrans.doBatch(strSql.toString()); } public OnTimeCreditIntf(String staffNo, String pswd, String path, String planXMLFileFN){ // if(this.conn == null) { // this.conn = this.getConnection(); // this.conn.setAutoCommit(true); // } this.staffNo = staffNo; this.pswd = pswd; this.path = path; this.planXMLFileFN = path + File.separator + planXMLFileFN; // 启动数据库连接 myDBTrans = new TranContext(); } public boolean isWorking() { return working; } public void setWorking(boolean working) { this.working = working; } public void run() { // 开始无限循环工作 long times = 0; int sleepTime = 60; while (working) { try { List curSubmitReport = getBJOnTimeCreditIntfSumbit(); String xmlFileName = Util.getAppTopFolderPath() + Const.CONFIG_XML_FILE_NAME; Config config = new Config(xmlFileName); sleepTime = config.sleep; for (int n = 0; n < curSubmitReport.size(); n++) { try { Date curDate = new Date(); HashMap planInfo = (HashMap) curSubmitReport.get(n); String requestId = (String) planInfo.get("ORDER_SERIAL_NBR"); String servId = (String) planInfo.get("SERV_ID"); String synType = (String) planInfo.get("OWE_BUSINESS_TYPE_ID"); String stateTime = (String) planInfo.get("STATE_DATE"); String curBalance = (String) planInfo.get("BALANCE"); String creditValue = (String) planInfo.get("CREDIT"); String random = String.valueOf(Math.random()).substring(2,10); Date currentTime=new Date(); SimpleDateFormat formatter=new SimpleDateFormat("yyyyMMddHHmmss"); String time=formatter.format(currentTime); String serial = time + random + "10" + "02"; WebSoapBindingImplServiceStub.OnTimeCreditControlReq onTimeCreditControlReq = new WebSoapBindingImplServiceStub.OnTimeCreditControlReq(); WebSoapBindingImplServiceStub.OnTimeCreditControl onTimeCreditControl = new WebSoapBindingImplServiceStub.OnTimeCreditControl(); onTimeCreditControlReq.setRequestId(serial); onTimeCreditControlReq.setServId(servId); onTimeCreditControlReq.setStateTime(stateTime); onTimeCreditControlReq.setSynType(Integer.parseInt(synType)); onTimeCreditControlReq.setInterfaceId(""); onTimeCreditControlReq.setCurBalance(curBalance); onTimeCreditControlReq.setCreditValue(creditValue); onTimeCreditControl.setIn0(onTimeCreditControlReq); logger.info("**OnTimeCreditControl**请求参数如下:" + "\n RequestId(请求流水): " + onTimeCreditControlReq.getRequestId() + "\n ServId(用户标识): " + onTimeCreditControlReq.getServId() + "\n SynType(同步类型): " + onTimeCreditControlReq.getSynType() + "\n curBalance(实时结余): " + onTimeCreditControlReq.getCurBalance() + "\n creditValue(用户信用度): " + onTimeCreditControlReq.getCreditValue() + "\n StateTime(状态时间): " + onTimeCreditControlReq.getStateTime()); String result = callOnTimeCreditIntfWebServices(onTimeCreditControl,config); if("0".equals(result)) { insertBJOnTimeAWorkOrderLog(requestId,serial); deleteBJOnTimeCreditIntfPlan(requestId); logger.info("=========OnTimeCreditControl successful,servId:"+servId+"========="); } else { myDBTrans.roolback(); updateBJOnTimeCreditFailPlan(requestId,result,serial); logger.info("=========OnTimeCreditControl failure,servId:"+servId+"当前流水执行失败!!!" ); } myDBTrans.commit(); // 关闭数据集 try { myDBTrans.close(); } catch (Exception e) { e.printStackTrace(); } } catch (RuntimeException e) { logger.info("=========failure=========当前条目计划执行失败!!!" ); e.printStackTrace(); myDBTrans.roolback(); myDBTrans.close(); } } } catch(Exception ex) { ex.printStackTrace(); Util.outPutInfo("未知错误发生" + ex.getMessage()); } // 关闭数据集 try { myDBTrans.close(); } catch (Exception e) { e.printStackTrace(); } // 睡眠一段时间后再工作 try { sleep(sleepTime); myDBTrans.freeCon(); myDBTrans.initConnection(); } catch(InterruptedException e) { Util.outPutInfo("线程睡眠被打断,程序继续执行: " + e.getMessage()); e.printStackTrace(); } } } private String callOnTimeCreditIntfWebServices(WebSoapBindingImplServiceStub.OnTimeCreditControl onTimeCreditControlReq,Config config) { try { WebSoapBindingImplServiceStub stub = new WebSoapBindingImplServiceStub(config.wsEndpoint); WebSoapBindingImplServiceStub.OnTimeCreditControlResponse onTimeCreditControlResp = stub.onTimeCreditControl(onTimeCreditControlReq); logger.info("result is: \n"+onTimeCreditControlResp.getOnTimeCreditControlReturn().getResult()); String result = onTimeCreditControlResp.getOnTimeCreditControlReturn().getResult(); if("0".equals(result)) return "0"; else return onTimeCreditControlResp.getOnTimeCreditControlReturn().getErrorMessage(); } catch(Exception e) { e.printStackTrace(); return "5000"; } } public static void main(String[] args) { String path = Util.getAppTopFolderPath(); String user = "jlz"; String pswd = "1q2w3e4r"; Thread thread = new OnTimeCreditIntf(user, pswd, path, Const.SUBMIT_PLAN_XML_FILE_NAME); thread.setDaemon(false); ((OnTimeCreditIntf) thread).setWorking(true); thread.start(); // 主线程进入无限睡眠状态,其创建的子线程 thread 继续工作 try { Thread.sleep(Long.MAX_VALUE); } catch(InterruptedException e) { System.out.println("主线睡眠状态被打断,程序继续执行...\n" + e.getMessage()); } // 当主线程睡眠被打断时,程序结束,并设置子线程状态,让其在完成必要工作后也结束 ((OnTimeCreditIntf) thread).setWorking(false); } }
相关推荐
总结起来,"简单的多线程示例delphi7"这个项目提供了一个基础的多线程实现,通过TThread类创建新线程,并通过重写Execute方法来定义线程任务。开发者可以通过学习这个示例,理解如何在Delphi 7中进行多线程编程,以...
"多线程示例.rar"是一个包含完整源码和编译好的示例程序的压缩包,目的是帮助开发者理解如何在Delphi中创建和管理多线程。以下是一些关键的知识点: 1. **TThread 类**:Delphi的`System.Classes`单元中定义了`...
通过上述讨论,我们可以看到,"VB 稳定多线程示例源码"提供的资源对于学习和理解VB中的多线程编程至关重要。它不仅展示了如何创建和管理线程,还可能包含了如何实现线程同步和异常处理的示例,这对于任何希望提高VB...
在本示例"bcb 多线程示例 MutilThread(生产者与消费者)"中,我们将探讨 Borland C++ Builder (bcb) 平台上的线程应用,特别是生产者-消费者问题的解决方案。 生产者-消费者问题是多线程编程中的一个经典案例,它...
本示例旨在为初学者提供一个全面理解Java多线程的起点。通过学习这个实例,你可以掌握如何创建和管理线程,理解线程同步与通信的重要性,以及如何处理线程安全问题。 1. **线程的创建** Java提供了两种创建线程的...
"嗷嗷叫的老马"分享的示例可能就是利用这个组件来创建和管理线程。使用ActiveX EXE,开发者可以创建一个单独的进程,该进程在后台运行并与其他组件通信,从而实现多线程。这种方式的优点在于代码结构清晰,易于管理...
`threads.pbl`和`threads.pbt`文件很可能是包含了这个多线程示例的相关类库和项目文件。 首先,我们需要创建一个`Thread`对象,这可以通过调用`Create`函数来实现。然后,我们需要定义一个回调函数,这个函数将在子...
Java中的多线程有三种实现方式: 1.继承Thread类,重写run方法。Thread本质上也是一个实现了Runnable的实例,他代表一个线程的实例,并且启动线程的唯一方法就是通过Thread...本示例演示和wait和sleep、线程锁的使用。
本文将深入探讨C++11中的多线程特性,并通过描述中的示例来展示如何创建和管理线程。 首先,要使用C++11的多线程功能,你需要包含`<thread>`头文件。在这个头文件中,定义了一个`std::thread`类,它是创建新线程的...
等线程示例学习 在计算机编程中,线程是程序执行的基本单元,它允许一个程序同时执行多个任务。在多核或多处理器系统中,线程可以充分利用硬件资源,提高程序的运行效率。"等线程示例学习"着重探讨的是如何在编程中...
### C# 多线程示例详解 #### 标题:C# 多线程示例 本示例提供了一个简单且易于理解的C# 多线程编程案例,非常适合初学者快速掌握C# 中多线程的基本用法。通过实际代码演示了如何在C# 中创建线程、管理线程之间的...
通过学习和实践这些C#多线程示例,开发者能够更好地掌握如何在应用程序中有效地使用多线程,提高程序的性能和用户体验。在实际项目中,应根据任务特性和系统需求选择合适的线程管理策略,确保程序的稳定性和效率。
在这个主题中,我们将深入探讨一个多线程示例程序以及在使用多线程时可能遇到的常见问题。 首先,我们来看标题中提到的"一个多线程示例程序"。在C++Builder中,创建多线程通常涉及使用`TThread`类,这是VCL(Visual...
QT开线程示例 在QT编程中,多线程技术是提高应用程序性能和响应性的重要手段。QT库提供了一套完整的线程支持,使得开发者能够轻松地在Qt应用程序中创建和管理线程。本示例将深入讲解如何在QT中开启线程,并通过实例...
在实际编程中,多线程示例通常包括: 1. 并行计算:如矩阵乘法、大数据处理等,将任务分解为多个子任务,由不同线程并行处理。 2. 异步I/O:线程负责处理I/O操作,主线程继续执行其他任务,如网络请求、文件读写。 3...
本资源“powerbuilder多线程示例10个thread”提供了十个具体的PowerBuilder多线程应用实例,适用于PowerBuilder 9.0版本。这些示例将帮助开发者深入理解如何在PB中实现和管理线程,以优化程序性能。 1. **线程基础...
综上所述,"powerbuilder多线程示例"不仅涵盖了多线程的基本原理,还可能包含了一些实战经验和高级技巧。通过学习和实践这个示例,开发者可以更好地理解和掌握PowerBuilder中的多线程编程,从而编写出更加高效和稳定...
本文将通过分析“多线程示例Test.jar”这一实例,深入探讨多线程的相关概念、实现方式以及在实际应用中的注意事项。 一、多线程基础 1. 线程与进程:在操作系统中,进程是资源分配的基本单位,而线程则是执行调度...