2

After deployment of a java project in spring hibernate can i call a jsp automatically after some interval without sending any request to the server?

Can We use .bat file or .exe ?

Any suggestion

Thanks

  • What do you mean by "...without sending any request to the server?" ? – Bimalesh Jha Oct 18 '13 at 07:14
  • Actually i am retrieving mail and dumping in my local db and almost 50 mails is coming in every 15 minutes, so some times browser is not on but server is always on. That's why i want to run some method in background after some interval...... – user2893493 Oct 18 '13 at 07:23
  • 1
    You should read Task scheduling in Spring http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/scheduling.html – Keerthivasan Oct 18 '13 at 07:48

4 Answers4

0

use a filter monitor request then call a jsp

mqshen
  • 501
  • 3
  • 11
0

You should spawn a Thread and let it do the email retrieval and dumping emails to DB. You could start this Thread on application deployment using a ServletContextListener implementation registered in your web.xml. Following articles might help you to get a more detail understanding.

http://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html

http://www.mkyong.com/servlet/what-is-listener-servletcontextlistener-example/

Dev Blanked
  • 8,555
  • 3
  • 26
  • 32
  • Prior to JavaEE7 you should not run your own threads. In Java EE7 you have server managed threads. – Thomas Oct 18 '13 at 07:51
  • @Thomas do u mean it's not recommended to create your own Threads ? – Dev Blanked Oct 18 '13 at 07:58
  • Exactly, though many people do, and it may be fine if you really know what you are doing. (Esp. in servlet-only/tomcat/spring context quartz/spring scheduling is a fine option. But when you run full-fledge EE stack I recommend caution.) See as well: http://stackoverflow.com/questions/533783/why-spawning-threads-in-java-ee-container-is-discouraged/533847#533847 – Thomas Oct 18 '13 at 07:59
  • @Thomas thx for the info. in relation to EJB's it makes perfect sense. But if you have a plain web application and you want some things to happen in the background then i find no reason not to use threads. – Dev Blanked Oct 18 '13 at 08:06
0

As I know a server can not call JSP automatically (can only to perform auto compilation). It task is out of nature of server. Application server cloud execute jsp pages only by requests. You can develop a tool (in java as example) which could simulate a request to the server by requesting some jsp page or execute a .class file of jsp page directly. As another solution is to send http request to the server by telnet from command line which you can put into a .bat file and execute it after deployment. Also you can use http://curl.haxx.se/ tool to perform any type requests from command line to your server.

telnet example:

telnet 127.0.0.1 8080

then

GET /myapp/index.jsp

Eugene Kirin
  • 568
  • 3
  • 16
0

If you want to use the request to trigger server side behaviour, you should really consider to use an EJB-Timer as an alternative.

The other option is to use your infrastructure (cron, windows scheduler) to make a request.

Thomas
  • 11,272
  • 2
  • 24
  • 40