代码如下,现在是通过输入回车控制task1,task2的结束(只能同时),请问能否通过前台JSP页面输入日期参数控制task1,task2的不同时间结束?改如何修改代码,求教.import java.net.*;
import java.io.*;
import java.util.*;public class SMStest {
public static void main(String args[])
throws java.io.IOException { TimerTask task1 = new TimerTask() {
public void run() { System.out.println("task1准备发送短信"); try
{
//指向NOWSMS短信服务的URL,GB2312简体中文编码
URL sms1 = new URL("http://127.0.0.1:8800/?PhoneNumber=+8613918571358&Text=SMS测试&charset=GB2312" );
InputStream in1 = new BufferedInputStream(sms1.openStream( ));
System.out.println("sms1发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}//end Run
};//end task1
TimerTask task2 = new TimerTask() {
public void run() {
System.out.println("task2准备发送短信");
try
{
//指向NOWSMS彩信服务的URL,GB2312简体中文编码 URL mms1 = new URL("http://127.0.0.1:8800/Send%20MMS%20Message.htm" );
InputStream ina = new BufferedInputStream(mms1.openStream( ));
System.out.println("mms2发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}//end Run };//end task2
Timer timer1 = new Timer();
Timer timer2 = new Timer(); Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,12);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 0);
Date time1 = calendar.getTime(); Date time2 = calendar.getTime();
timer1.schedule(task1,time1,1000);
timer2.schedule(task2,time2,10000);
System.out.println("Press ENTER to stop the task");
System.in.read(new byte[10]);
timer1.cancel();
timer2.cancel(); System.out.println("短信发送终止");
}
}
import java.io.*;
import java.util.*;public class SMStest {
public static void main(String args[])
throws java.io.IOException { TimerTask task1 = new TimerTask() {
public void run() { System.out.println("task1准备发送短信"); try
{
//指向NOWSMS短信服务的URL,GB2312简体中文编码
URL sms1 = new URL("http://127.0.0.1:8800/?PhoneNumber=+8613918571358&Text=SMS测试&charset=GB2312" );
InputStream in1 = new BufferedInputStream(sms1.openStream( ));
System.out.println("sms1发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}//end Run
};//end task1
TimerTask task2 = new TimerTask() {
public void run() {
System.out.println("task2准备发送短信");
try
{
//指向NOWSMS彩信服务的URL,GB2312简体中文编码 URL mms1 = new URL("http://127.0.0.1:8800/Send%20MMS%20Message.htm" );
InputStream ina = new BufferedInputStream(mms1.openStream( ));
System.out.println("mms2发送完毕");
}
catch (MalformedURLException e)
{
System.err.println(e);
}
catch (IOException e)
{
System.err.println(e);
}
}//end Run };//end task2
Timer timer1 = new Timer();
Timer timer2 = new Timer(); Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,12);
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 0);
Date time1 = calendar.getTime(); Date time2 = calendar.getTime();
timer1.schedule(task1,time1,1000);
timer2.schedule(task2,time2,10000);
System.out.println("Press ENTER to stop the task");
System.in.read(new byte[10]);
timer1.cancel();
timer2.cancel(); System.out.println("短信发送终止");
}
}
再来构造你的Timer,这样就可以实现.
下次拒绝回答你的问题.
hehe