Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

using java.util.Timer in JSP

im using JDK 1.4

my code is :

<%@ page import="javax.telephony.*" %>
<%@ page import="java.util.Timer" %>
<%@ page import="java.util.TimerTask" %>
<%@ page import="Callback" %>
     class CounterTimerTask extends java.util.TimerTask {
        * Date format used in message.  Includes milliseconds.

        public static final SimpleDateFormat FMT = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS aa");

        private String name;
        private Date sked;
        private Callback cb;

        public CounterTimerTask(String name, Date sked, Callback cb) {
  = name;
           this.sked = sked;
           this.cb = cb;

        public void run() {
           System.out.println("Starting " + name);
           System.out.println(FMT.format(sked) + " Thread " + name);

          try {
          } catch (Exception ex) {
              System.out.println("ERROR: " + ex.getMessage());

          while(!cb.isDone()) {
              try {
              } catch(Exception ex) {}


     Callback c = new Callback();
     String dateStr = request.getParameter("date");
     String timeStr = request.getParameter("time");

     java.text.SimpleDateFormat date_format = new java.text.SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
    Date sked = date_format.parse(dateStr + " " + timeStr);

     Timer timer = new Timer();
    TimerTask task = new CounterTimerTask("callback");
    timer.schedule(task, sked);
Result: <%=c.getLastError()==null?"Callback Complete":c.getLastError()%>
<A HREF="index.html">Back</A>

its giving me :

Exception :

javax.servlet.ServletException: sun/tools/javac/Main
     at org.apache.jasper.servlet.JspServlet.service(
     at javax.servlet.http.HttpServlet.service(


root cause

java.lang.NoClassDefFoundError: sun/tools/javac/Main
     at org.apache.jasper.compiler.SunJavaCompiler.compile(
     at org.apache.jasper.compiler.Compiler.compile(


does this mean i cant use java.util.Timer() in JSP?
  • 2
  • 2
1 Solution
iboAuthor Commented:
i dont have any points right now :P credit?
iboAuthor Commented:
btw since i didnt put interval (for multiple repetitions), i dont need to call cancel() right?
This error is because of the server couldn't find tools.jar.
You need to have tools.jar in your classpath.
The tools.jar is located in {jdk path}/lib/
> btw since i didnt put interval (for multiple repetitions), i dont need to call cancel() right?
You're right. It only get execution one time.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now