import java.net.*;import java.io.*;import java.util.*;public class SMStest {
public static void main(String args[])
throws java.io.IOException {
TimerTask task = new TimerTask() {
public void run() {
System.out.println("准备发送短信");
try
{
//发送短信
URL sms1 = new URL("http://127.0.0.1:8800/?PhoneNumber=+8613918571358&Text=SMS测试&charset=GB2312" ); //指向NOWSMS服务的URL
InputStream in1 = new BufferedInputStream(sms1.openStream( ));
System.out.println("sms1发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
System.out.println("短信发送成功!"); }
};
Timer timer = new Timer();
timer.schedule(task,5000,10000);//定时发送10s
System.out.println("Press ENTER to stop the task");
System.in.read(new byte[10]);
timer.cancel(); System.out.println("短信发送终止"); }
}以上代码实现了通过NOWsms的软件进行定时短信发送,请问若现在要进行短信群发,应如何修改代码?谢谢用多线程实现
public static void main(String args[])
throws java.io.IOException {
TimerTask task = new TimerTask() {
public void run() {
System.out.println("准备发送短信");
try
{
//发送短信
URL sms1 = new URL("http://127.0.0.1:8800/?PhoneNumber=+8613918571358&Text=SMS测试&charset=GB2312" ); //指向NOWSMS服务的URL
InputStream in1 = new BufferedInputStream(sms1.openStream( ));
System.out.println("sms1发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
System.out.println("短信发送成功!"); }
};
Timer timer = new Timer();
timer.schedule(task,5000,10000);//定时发送10s
System.out.println("Press ENTER to stop the task");
System.in.read(new byte[10]);
timer.cancel(); System.out.println("短信发送终止"); }
}以上代码实现了通过NOWsms的软件进行定时短信发送,请问若现在要进行短信群发,应如何修改代码?谢谢用多线程实现
把你要做的事做成一个类,然后自定义一个线程
把这个类的对象做为参数传入这个线程
然后线程起动了
因为你每个线程传的参数应该会不一样,所以很多线程同时起动了
发了不同的信息给不同的人,
这应该是你想实现的功能吧