最近系统中用到了定时发送短信功能,目前的做法是用系统自带的Timer类写一个定时任务,将要发送的短信存入一个数据库表中,定时发送。硬件采用的是市面上常见的wavecom短信猫
现有如下问题求解:系统不定时发生如下异常"GSM: Invalid CREG response.",随后的短信就发不出去了。
我个人感觉似乎有两个问题:1.好像Timer碰到了异常后就停了,如果是这样,我该怎么办
2.GSM: Invalid CREG response.",这个异常应该怎么避免
下面是我用到的发送类,Timer会定时从数据库取得需要发送的短信,然后通过一个循环来调用这个类
[code="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();
}
[/code]
[b]问题补充:[/b]
to ddzhang: 它有异常倒也无所谓,大不了我等会再发这条短信,问题是好像一有这个异常,整个程序就停下来了,不知您当时是怎么解决的