title: Java. Getting IOException after trying to print on JSP page using simple scheduler(Timer, TimerTask). Need help
body: <p>i'm trying to make simple scheduler using Timer and TimerTask classses see the code below, inside of the task i just want to print "Hello, World!" on the page, but it throws IOException: Stream closed. Please help!</p>
  
  <p>JSP page code:</p>
  
  <pre><code>&lt;% Test t = new Test(out);%&gt;
  </code></pre>
  
  <p>Test class code:</p>
  
  <pre><code>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);
      }
  }
  </code></pre>
  
  <p>LpdbTask code:</p>
  
  <pre><code>public class LpdbTask extends TimerTask{
      public JspWriter out;
      public void run(){
          try {
              out.println("Hello, World!");
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>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)
  </code></pre>