Solved

using java.util.Timer in JSP

Posted on 2002-03-20
4
381 Views
Last Modified: 2010-04-01
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) {
           this.name = name;
           this.sked = sked;
           this.cb = cb;
        }

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

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

          while(!cb.isDone()) {
              try {
                  Thread.sleep(500);
              } catch(Exception ex) {}
          }

          //cancel();

        }
     }
%>
<%
     Callback c = new Callback();
     c.setFirstLeg(request.getParameter("firstleg"));
     c.setSecondLeg(request.getParameter("secondleg"));
     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);
%>
<BR>
Result: <%=c.getLastError()==null?"Callback Complete":c.getLastError()%>
<BR>
<A HREF="index.html">Back</A>


------
its giving me :

Exception :

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

---

root cause

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

---------


does this mean i cant use java.util.Timer() in JSP?
0
Comment
Question by:ibo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:ibo
ID: 6884771
i dont have any points right now :P credit?
0
 
LVL 3

Author Comment

by:ibo
ID: 6884778
btw since i didnt put interval (for multiple repetitions), i dont need to call cancel() right?
0
 
LVL 6

Expert Comment

by:kotan
ID: 6914694
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/
0
 
LVL 6

Accepted Solution

by:
kotan earned 20 total points
ID: 6914706
> 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.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
Popular third-party chat platforms like Slack, Discord, and Telegram are just a few of the many new productivity applications that are being hijacked by cybercriminals to create command-and-control (C&C) communications infrastructures for their malw…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question