Timer类定时任务异常程序停下来怎么解决?

分享
最近系统中用到了定时发送短信功能,目前的做法是用系统自带的Timer类写一个定时任务,将要发送的短信存入一个数据库表中,定时发送。硬件采用的是市面上常见的wavecom短信设备

现有如下问题求解:系统不定时发生如下异常"GSM: Invalid CREG response.",随后的短信就发不出去了。
我个人感觉似乎有两个问题:1.好像Timer碰到了异常后就停了,如果是这样,我该怎么办
2.GSM: Invalid CREG response.",这个异常应该怎么避免

to ddzhang: 它有异常倒也无所谓,大不了我等会再发这条短信,问题是好像一有这个异常,整个程序就停下来了,不知您当时是怎么解决的

下面是我用到的发送类,Timer会定时从数据库取得需要发送的短信,然后通过一个循环来调用这个类

java代码:

public void doIt(String number, String msgs) throws TimeoutException, GatewayException, SMSLibException, IOException, InterruptedException {

                Service srv;
                OutboundMessage msg;
                OutboundNotification outboundNotification = new OutboundNotification();

                srv = new Service();

                SerialModemGateway gateway = new SerialModemGateway("modem.com1",
                                "COM1", 9600, "wavecom", "17254");
                gateway.setInbound(true);
                gateway.setOutbound(true);
                gateway.setSimPin("0000");
                gateway.setOutboundNotification(outboundNotification);
                srv.addGateway(gateway);
                srv.startService();


                msg = new OutboundMessage(number, msgs);// 手机号码,和短信内容
                msg.setEncoding(MessageEncodings.ENCUCS2);// 这句话是发中文短信必须的
                srv.sendMessage(msg);
                srv.stopService();

        }


任务不要用jdk自带的Timer类来实现,用quartz框架
短信设备二次开发 2022-04-05 0 0

admin

  • 注册时间 : 2022-03-30 04:08:47
  • 邮箱地址 : admin@tenghengkeji.com
  • 此页面用于展示用户的基本上资料信息

回帖 ( 0 )