I developed an web application using java spring mvc. Now i want to deploy the application on tomcat server and want the application to run in a certain period of time in a day. Say, the application will run from 10:00 AM to 6:00 PM everyday and other time of the day the application cannot be used. I have searched if anything can be done with tomcat server 6 where i want to deploy my application but unable to get any solution or clue how to achieve the purpose. So, my question is how can i implement what i wanted to do? Any solution, samples or ideas will be much helpful to complete the task.
-
I think scheduler is the thing you want.and the best is quartz scheduler Example :-http://www.mkyong.com/tutorials/quartz-scheduler-tutorial/ – Akshay jain Aug 31 '15 at 06:40
-
I solved the issue by using a custom interceptor which extends the HandlerInterceptorAdapter of spring framework. Still thanks for the quartz scheduler suggestion. It may not have come handy this time but sure will be useful in future. – Junaid Aug 31 '15 at 11:51
2 Answers
I think you are trying to solve your problem using your infrastructure instead of using your application where it should be solved.If the requirement is to not have the application available during a certain period of time, which is a business requirement, code a solution for it. You could for example not allow logins if the login falls outside the specified time period and then instead display a message to a user. Existing sessions could be intercepted using a handler and then invalidating the session forcing a re-login.
Another solution would be to run a cron job on the server, which stops Tomcat at a specified time and starts it back up again. This would not be advisable as your users will not know of the operating times and most probably assume something is wrong.

- 189
- 8
-
I finally implemented the mechanism by using custom interceptor which extends HandlerInterceptorAdapter of spring framework. Giving my solution as an answer in this thread so it can help others who may face similar kind of challenge. – Junaid Aug 31 '15 at 11:56
-
Well i tried to mark the answer as accepted but it says i can mark my answer as accepted after two days. – Junaid Sep 01 '15 at 08:40
Finally i have implemented the mechanism of running my web application on tomcat server for certain period of time in a day. I used an custom interceptor by extending HandlerInterceptorAdapter of spring framework to intercept all servlet requests. Then in the preHandle function, all servlet requests have been haul and then checked current time if it is within the time period the application will run. If it is within time period, then the requests are allowed to proceed, else redirected to a specific page prompting user they can't access the application currently.

- 1,179
- 2
- 18
- 35