| 发表于:2007-06-29 11:24:37 楼主 |
问题是我在程序中做了一个线程监测与mq服务器的连接,一旦连接中断则重新连接,但是在现成运行的过程中,偶尔会报2059:应用程序错误,不知道为什么,应该不是连接数已满的问题,请大侠们帮助解决一下,源代码如下: while (conn_flag && !isrunning) { try { //线程正在运行 isrunning = true; //if (count == short.maxvalue - 1) //{ // count = 0; //} //mqmanager.connqueuemanager(); mqmanager.initiate(); try { count = count + 1; } catch (exception ex) { } try { srv.writeln(count.tostring()); } catch (exception ex1) { } //若连接成功则跳出循环,线程不再运行 //this.conn_flag = true; //线程取得正常的运行结果,不需要再次运行 isrunning = false; try { thread.sleep(1 * 1000); } catch (exception ex2) { } if (count == 1) { globalvariable.setglobalvariable( "mq ", mqmanager); srv.writeln( "连接mq服务器成功!可以进行读写操作! "); globalvariable.writeeventlog( "mq ", "连接mq服务器成功 ", eventlogentrytype.information); string auto = srv.configuration[ "autorun "]; if (bool.parse(auto)) { listhread = new theadmanager( "rcvmq "); listhread.startlisten(); globalvariable.setglobalvariable( "listenthread ", listhread); } if (globalvariable.getglobalvariable( "player ") != null) { //停止报警 //soundplay play = (soundplay)globalvariable.getglobalvariable( "player "); //play.stopplay(); } this.iscatch = true; } } //以下为对连接过程中出现异常的处理 catch (mqexception ex) { count = 0; if (globalvariable.getglobalvariable( "mq ") != null) { globalvariable.remove( "mq "); } //modify-07-04-19 //if (globalvariable.getglobalvariable( "ims ") != null) //{ // globalvariable.remove( "ims "); //} if (!iscatch) { globalvariable.writeeventlog( "mq ", "连接mq服务器异常 " + "异常代码 " + ex.reasoncode.tostring() + "异常信息 " + ex.message, eventlogentrytype.failureaudit); player = (soundplay)globalvariable.getglobalvariable( "player "); if (player != null) { player.playsound(); } this.iscatch = true; } try { //出现异常关闭监听线程 theadmanager thread = (theadmanager)globalvariable.getglobalvariable( "listenthread "); if (thread != null) { thread.closelisten(); } } catch { srv.writeln( "监听线程未启动 "); } string name = thread.currentthread.name; //srv.writeln( "连接mq服务器的过程中出现异常,请查看日志!日志位置位于安装目录下mq文件夹下 "+ex.tostring()); switch (ex.reasoncode) { //连接断开 case 2009: //队列管理者无效或未知 case 2058: //队列管理者无效 case 2059: //意外的错误发生 case 2195: //服务器正在启动 case 2161: //服务器正在关闭 case 2162: //阻塞线程三秒,之后重新连接,重复3次,如果连接不上,置空 //for (int i = 0; i < 3; i++) { srv.writeln( "正在重新连接mq服务器!若没有恢复请及时联系mq服务器管理员! " + ex.tostring()); //线程十秒后再次运行 thread.sleep(5 * 1000); fm = new filemanager( "mq\\mqlog.log "); fm.writestringtofile(datetime.now.tostring() + " 连接mq服务器的过程中出现问题 " + ex.message.tostring() + "错误代码: " + ex.reasoncode + "错误提示: " + ex.tostring()); fm.closestreamwriter(); } //线程一次运行已经结束,但未得到预期的结果,需要再次运行 isrunning = false; conn_flag = true; mqmanager.setqueuemanager(null); break; //无权访问服务器队列管理者 case 2035: //线程不需要再次运行,直接写入日志文件,并报警 conn_flag = false; fm = new filemanager( "mq\\mqlog.log "); fm.writestringtofile(datetime.now.tostring() + " 无权访问mq服务器队列管理者 " + ex.message.tostring() + "错误代码: " + ex.reasoncode); fm.closestreamwriter(); mqmanager.setqueuemanager(null); break; //其他异常 default: //线程不需要再次运行,直接写入日志文件,并报警 conn_flag = true; fm = new filemanager( "mq\\mqlog.log "); fm.writestringtofile(datetime.now.tostring() + " 连接mq服务器的过程之中出现未知的异常 " + ex.message.tostring() + "错误代码: " + ex.reasoncode); fm.closestreamwriter(); mqmanager.setqueuemanager(null); break; } } finally { //关闭mq服务器队列管理器 mqmanager.closemanager(); } |
|
|
|
|