Improve company productivity with a Business Account.Sign Up

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

Make web application temporarily unavailable while data refresh takes place

Hello All,

We are working on an application in which data needs to be refreshed on a regular basis. Currently the application server is shutdown before the data refresh takes place and started again when data has been refreshed. But the problem is that due to certain reasons the application take a huge amount of time to start up. What we are looking at now is to find out if the web application can be flagged as unavailable for a short duration till the data refresh takes place. Is there some way this can be done. We are using Weblogic 8.1.

The data refresh part is a Java batch job (i.e a standalone program) that reads some xml files and inserts data into a SQL Server database (the database is re-created and the old one is archived or deleted). This batch job need not reside on the same host as the database server or application server. It could be on a seperate host on its own. When the application starts up on Weblogic it reads all the data from the SQL Server database and caches it into memory in suitable java objects. It caches each and every record.

These are the questions that we are facing.
1] How do we notify the application that it should stop servicing any requests from the java batch job (not stopping the app server).
2] How to we suspend the web application for a short duration
3] How do we notify the application that it should start servicing any requests from the java batch job (not restarting the app server).
4] How do we kill all the user sessions that are currently active.
5] How can the cache in memory be updated to reflect the new data.

Its a very complex problem and I dont know if its even possible. Even if I can get answers to a few of the above questions I would appreciate it very much.

1 Solution
I have a thread with watches a properties file.  When that properties file changes, it reloads the file into the (taking the old values it knew about out first)

Then, I have a Filter in my webapplication.  Each request it gets, it checks the "system.down" property (a String)  If it exists, it redirects the user to a holding page, and displays the string.

So shutting down the website nicely, is just a matter of uncommenting a property in a properties file :-)

And waiting for the thread to pick up that the file has changed :-)

another solution could be to send a message to stop to the system (like done in Tomcat shutdown).
And when this message is reached, all the request could be redirected to some other place (like TimYates told).

I assume you are using struts. The problem will be easy to solve then Here are the steps you should take, obviously, your java program will flag the maintainance activity using may be a .lock file or by specially putting something inside a file

1. Extend the Action class by MyAction class.
2. In its execute() method, check for the flag you have set(.lock exists or not for eg)
    If you find the flag set, then do these
        a. request.getSession().invalidate()
        b. redirect the request to an error jsp.
    else If all is well, just return from the method.
3. Extend all your custom Action classes to extend MyAction instead.
4. In the execute method of each class, just call super.execute() on the FIRST line.

When your maintenance activity is done, just delete the .lock file and your applcation will resume operation.
Hope this addresses most of your questions :)
bhayzoneAuthor Commented:
Hi All,

Sorry for replying so late. I liked your idea of using a filter. I have come up with a way to suspend the application and start it again without restarting the webserver. I simply make my struts AcitonServlet throw an UnavailableException, which takes a paramereter to specify how long do you want the servlet to be unavailable. Do you think this is a good way to do it.

    throw new UnavailableException (50000);

I cannot use the option suggested by kumvjuec because the application is one which has already been developmed and we are making enhancements. It wont be possible to modify each and every existing Action class.

We are now working on a workaround for this task. For example, we now wont be replacing the already existing cached data with the new one, but will maintain two cached objects. All new requests will pick up data from the new cache object while the old object will service the old data. Once there are no more sessions using the old object, it will be discarded and everyone will now use the new object.

There will be an array of cache objects. An index in each users session will indicate which of the cache objects to use. I dont know if what we have come up with is a good approach or not.

I think the notification to the web applicaiton to start and stop accepting requests temporarily is out. There is no requirement for a notification mechanism because we will now be providing the trigger to start caching manually (probably through a button on the page)

It would be of great help if you could identify some potential problems with the approach that we are taking.

For my own knowledge, is there anyway that we can kill all user sessions? I know of a way that can be done, but for that it is essential that struts be implemented properly.
> Do you think this is a good way to do it.

You could just put the bit in the Filter, so that for each request, it can throw an UnavailableException before it even gets to the actions, you can then define an Exception handler in the struts-config file, so that when unavailable, it forwards to a page that says the site is down :-)

> There will be an array of cache objects. An index in each users session will indicate which of the cache objects to use. I dont know if what we have come up with is a good approach or not.

That sounds ok!  By doing it this way, you won't have problems of users having stale objects in their session...  One thing to be careful of though, is if the cached object can be changed by the user, you might get problems with concurrency (someone writes at the same time as someone else, at the same time someone reads) ;-)

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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