我正在尝试使用 Timer 和 TimerTask 类制作简单的调度程序,请参见下面的代码,在任务内部我只想打印“Hello,World!” 在页面上,但它抛出 IOException: Stream closed。请帮忙!
JSP页面代码:
<% Test t = new Test(out);%>
测试类代码:
public class Test {
public Test(JspWriter out){
Timer timer = new Timer();
LpdbTask lTask = new LpdbTask();
lTask.out = out;
timer.scheduleAtFixedRate(lTask, 1000*5, 1000*60);
}
}
Lpdb任务代码:
public class LpdbTask extends TimerTask{
public JspWriter out;
public void run(){
try {
out.println("Hello, World!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
错误:
java.io.IOException: Stream closed
at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:312)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:342)
at org.apache.jasper.runtime.JspWriterImpl.print(JspWriterImpl.java:468)
at org.apache.jasper.runtime.JspWriterImpl.println(JspWriterImpl.java:576)
at scheduler.LpdbTask.run(LpdbTask.java:14)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)