- /**
- * Title: 加入线程
- * Description:
- * @date : 2006-3-3
- * @author : zhanglei
- * @version : 1.0
- */
- package server;
- import java.io.*;
- import java.util.*;
- import java.sql.*;
- /**
- *RecvThread 交换信息接收XML文件服务线程
- *@param1 线程启动时间
- *@param2 监控文件路径
- */
- class RecvThread
- implements Runnable {
- private DomXML DomXML = MainServer.DomXML;
- static int sumFile = 0; //处理文件合计数
- private int threadTime = 0; //线程延时时间
- private findfile FindFile = null;
- private int execFlag = 0; //执行SQL语句结果标识
- private File doFile = null; //备份移动后进行处理的文件
- private File errorFile = null; //异常XML文件移动
- private String filename = "";
- private String pathname = "";
- private StringBuffer log = new StringBuffer();
- private JdbcWork RkJw = new JdbcWork();
- // private int xmlListFlag = 0; //接收XML的list文件处理标识 0 未处理 1 处理成功 -1 处理失败
- private String threadNo = ""; //线程号
- private ListXML listXml = null;
- public RecvThread(String ThreadNo) {
- threadNo = ThreadNo;
- DomXML.GetBeginItem("receive");
- this.threadTime = GetThreadtime(DomXML.GetItemAttribute(threadNo, "threadtime").trim());
- this.pathname = DomXML.GetItemAttribute(threadNo, "path").trim();
- FindFile = new findfile(pathname);
- listXml = new ListXML();
- RkJw.ConnectDB();
- }
- //执行线程体
- public void run() {
- System.out.println("run");
- }
- //获得线程时间
- public static int GetThreadtime(String timeStr) {
- int threadtime = 1000;
- if (MyFunction.IsNumber(timeStr)) {
- threadtime = Integer.parseInt(timeStr);
- }
- return threadtime;
- }
- public static void main(String args[]) {
- //读入检验XML配置到内存
- try {
- DomXML configXml = new DomXML("config.xml");
- System.out.println("XML配置文件读取成功!");
- }
- catch (Throwable t) {
- System.out.println("检验XML配置文件读取错误!");
- }
- Thread RecvThread = new Thread(new RecvThread("no1"));
- RecvThread.start();
- /* //建立Jdbc数据库连接
- JdbcWork JW = new JdbcWork();
- if(JW.ConnectDB() == null) {
- System.out.println("数据库连接失败!");
- System.exit(1);
- }
- */
- //户籍变动处理,执行rk_change_people()
- // Thread TestThread = new Thread(new TestThread(1, ""));
- // TestThread.start();
- }
- }
- /*
- /**
- *ExecSqlThread 户籍变动处理,执行sql语句线程
- *@param1 线程启动时间
- *@param2 执行的SQL语句
- */
- class ExecSqlThread
- implements Runnable {
- private DomXML DomXML = MainServer.DomXML;
- private String threadNo = null;
- private int threadTime = 0; //线程延时时间
- private String sqlStr = null;
- private JdbcWork EsJw = new JdbcWork();
- public ExecSqlThread(String ThreadNo) {
- threadNo = ThreadNo;
- DomXML.GetBeginItem("execproc");
- this.threadTime = RecvThread.GetThreadtime(DomXML.GetItemAttribute(threadNo, "threadtime").trim());
- this.sqlStr = DomXML.GetItemAttribute(threadNo, "procname").trim();
- EsJw.ConnectDB();
- }
- public void run() {
- while (true) {
- try {
- EsJw.PstmtExecSql(sqlStr);
- EsJw.PstmtCommit();
- Thread.sleep(threadTime);
- }
- catch (Exception e) {
- SaveLog.SetInfo(sqlStr + "进程执行异常:" + e, 2);
- }
- }
- }
- }
- /**
- *TabHkThread 户籍变动处理,执行sql语句线程
- *@param1 线程启动时间
- *@param2 执行的SQL语句
- */
- class GetXmlThread
- implements Runnable {
- private DomXML DomXML = MainServer.DomXML;
- private String threadNo = null;
- private int threadTime; //线程延时时间
- private String xmlno;
- public GetXmlThread(String ThreadNo) {
- threadNo = ThreadNo;
- DomXML.GetBeginItem("GetXmlFile");
- this.threadTime = RecvThread.GetThreadtime(DomXML.GetItemAttribute(threadNo, "threadtime").trim());
- this.xmlno = ThreadNo; //DomXML.GetItemAttribute(threadNo, "xmltype").trim();
- }
- public void run() {
- while (true) {
- try {
- GetXmlFile getXmlFile = new GetXmlFile(xmlno);
- getXmlFile.Start();
- Thread.sleep(threadTime);
- }
- catch (Exception e) {
- SaveLog.SetInfo(xmlno + "生成XML文件异常:" + e, 2);
- }
- }
- }
- }
- /**
- *MyAddThread 自增加线程
- *@ThreadNo 线程启动序号
- */
- class MyAddThread
- implements Runnable {
- private DomXML DomXML = MainServer.DomXML;
- private String threadNo = null;
- private int threadTime; //线程延时时间
- private String xmltype;
- public MyAddThread(String ThreadNo) {
- threadNo = ThreadNo;
- DomXML.GetBeginItem("MyAddThread");
- this.threadTime = RecvThread.GetThreadtime(DomXML.GetItemAttribute(threadNo, "threadtime").trim());
- }
- public void run() {
- while (true) {
- try {
- new MyThreadClass();
- Thread.sleep(threadTime);
- }
- catch (Exception e) {
- SaveLog.SetInfo(xmltype + "MyAddThread线程异常:" + e, 2);
- }
- }
- }
- }
- //调试检测运行进程数量
- class Probe
- extends Thread {
- public Probe() {}
- public void run() {
- while (true) {
- Thread[] x = new Thread[100];
- Thread.enumerate(x);
- for (int i = 0; i < 100; i++) {
- Thread t = x[i];
- if (t == null) {
- break;
- }
- else {
- System.out.println(t.getName() + "/t" + t.getPriority()
- + "/t" + t.isAlive() + "/t" + t.isDaemon());
- }
- }
- }
- }
- }
addthread.java
最新推荐文章于 2022-05-29 18:24:59 发布