Java timer Web

Source: Internet
Author: User
Tags apache tomcat

 

 

It is common to execute tasks by using a timer. The following is a simple example:

 

The listener, timertask, and timer classes are used for implementation. In addition, Spring provides advanced timer implementation, which seems to be quarts.

 

For more information, see.

 

 

  1. Package com. Rx. timer;
  2. Import java. util. date;
  3. Import java. util. timertask;
  4. Public class mytask extends timertask {
  5. @ Override
  6. Public void run (){
  7. System. Out. println ("call at" + (new date ()));
  8. }
  9. }

 

  1. Package com. Rx. timer;
  2. Import java. util. timer;
  3. Import javax. servlet. servletcontextevent;
  4. Import javax. servlet. servletcontextlistener;
  5. Public class mylisten implements servletcontextlistener {
  6. Private timer = NULL;
  7. @ Override
  8. Public void contextdestroyed (servletcontextevent arg0 ){
  9. Timer. Cancel ();
  10. }
  11. @ Override
  12. Public void contextinitialized (servletcontextevent arg0 ){
  13. Timer = new timer (true );
  14. // Set the task schedule, start time, and interval.
  15. Timer. Schedule (New mytask (), 0, 1000*10 );
  16. }
  17. }

 

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Web-app id = "webapp_id" version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  3. <Display-Name>
  4. Webtimer </display-Name>
  5. <Listener>
  6. <Listener-class> com. Rx. Timer. mylisten </listener-class>
  7. </Listener>
  8. <Welcome-file-List>
  9. <Welcome-File> index. jsp </welcome-File>
  10. </Welcome-file-List>
  11. </Web-app>

 

 

  1. 2008-11-20 20:52:35 org. Apache. tomcat. util. digester. setpropertiesrule begin
  2. Warning: [setpropertiesrule] {server/service/engine/host/context} setting property 'source' to 'org. eclipse. JST. j2EE. server: webtimer 'did not find a matching property.
  3. 2008-11-20 20:52:35 org. Apache. Catalina. Core. aprlifecyclelistener init
  4. Information: The APR based Apache Tomcat native library which allows optimal performance in production environments was not found on the java. library. path: C:/program files/Java/jre1.6.0 _ 07/bin ;.; c:/Windows/Sun/Java/bin; C:/Windows/system32; C:/windows; C:/program files/Java/jre1.6.0 _ 07/bin/client; c:/program files/Java/jre1.6.0 _ 07/bin; C:/Windows/system32; C:/windows; C:/Windows/system32/WBEM; C: /program files/MIC Rosoft SQL Server/90/tools/binn/; C:/progra ~ 1/IBM/sqllib/bin; C:/progra ~ 1/IBM/sqllib/function; C:/progra ~ 1/IBM/sqllib/samples/repl; C:/IBM/installation Manager/Eclipse/LIB; C:/program files/MySQL Server 4.1/bin; C: /program files/tortoisesvn/bin; C:/program files/subversion/bin; C:/program files/stormii/codec; C:/program files/stormii; C: /program files/IDM computer solutions/ultraedit/
  5. 20:52:35 org. Apache. Coyote. http11.http11protocol init
  6. Information: initializing coyote HTTP/1.1 on http-8080
  7. 2008-11-20 20:52:35 org. Apache. Catalina. startup. Catalina Load
  8. Information: initialization processed in 795 MS
  9. 2008-11-20 20:52:35 org. Apache. Catalina. Core. standardservice start
  10. Information: starting service Catalina
  11. 2008-11-20 20:52:35 org. Apache. Catalina. Core. standardengine start
  12. Information: Starting Servlet Engine: Apache Tomcat/6.0.18
  13. 20:52:36 org. Apache. Catalina. loader. webappclassloader validatejarfile
  14. Information: validatejarfile (D:/eclipseworkspace /. metadata /. plugins/org. eclipse. WST. server. core/tmp0/wtpwebapps/webtimer/WEB-INF/lib/servlet-api.jar)-jar not loaded. see servlet spec 2.3, section 9.7.2. offending class: javax/servlet. class
  15. Call at Thu Nov 20 20:52:36 CST 2008
  16. 20:52:36 org. Apache. Coyote. http11.http11protocol start
  17. Information: Starting coyote HTTP/1.1 on http-8080
  18. 20:52:36 org. Apache. JK. Common. channelsocket init
  19. Information: JK: ajp13 listening on/0.0.0.0: 8009
  20. 2008-11-20 20:52:36 org. Apache. JK. server. jkmain start
  21. Description: JK running id = 0 time = 0/31 Config = NULL
  22. 2008-11-20 20:52:36 org. Apache. Catalina. startup. Catalina start
  23. Information: server startup in 654 MS
  24. Call at Thu Nov 20 20:52:46 CST 2008
  25. Call at Thu Nov 20 20:52:56 CST 2008
  26. Call at Thu Nov 20 20:53:06 CST 2008
  27. Call at Thu Nov 20 20:53:16 CST 2008
  28. Call at Thu Nov 20 20:53:26 CST 2008
  29. Call at Thu Nov 20 20:53:36 CST 2008
  30. Call at Thu Nov 20 20:53:46 CST 2008
  31. Call at Thu Nov 20 20:53:56 CST 2008
  32. Call at Thu Nov 20 20:54:06 CST 2008
  33. Call at Thu Nov 20 20:54:16 CST 2008
  34. Call at Thu Nov 20 20:54:26 CST 2008
  35. Call at Thu Nov 20 20:54:36 CST 2008
  36. Call at Thu Nov 20 20:54:46 CST 2008
  37. Call at Thu Nov 20 20:54:56 CST 2008
  38. Call at Thu Nov 20 20:55:06 CST 2008
  39. Call at Thu Nov 20 20:55:16 CST 2008
  40. Call at Thu Nov 20 20:55:26 CST 2008
  41. Call at Thu Nov 20 20:55:36 CST 2008
  42. Call at Thu Nov 20 20:55:46 CST 2008
  43. Call at Thu Nov 20 20:55:56 CST 2008
  44. Call at Thu Nov 20 20:56:06 CST 2008
  45. Call at Thu Nov 20 20:56:16 CST 2008
  46. Call at Thu Nov 20 20:56:26 CST 2008
  47. Call at Thu Nov 20 20:56:36 CST 2008
  48. Call at Thu Nov 20 20:56:46 CST 2008
  49. Call at Thu Nov 20 20:56:56 CST 2008
  50. Call at Thu Nov 20 20:57:06 CST 2008
  51. Call at Thu Nov 20 20:57:16 CST 2008

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.