Make web application temporarily unavailable while data refresh takes place

Posted on 2004-08-05
Last Modified: 2010-03-31
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.

Question by:bhayzone
LVL 35

Expert Comment

ID: 11725068
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 :-)

LVL 12

Expert Comment

ID: 11725252
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).


Expert Comment

ID: 11791797
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 :)

Author Comment

ID: 11807246
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.
LVL 35

Accepted Solution

TimYates earned 500 total points
ID: 11807870
> 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) ;-)


Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 80
Apps blocked by Java 9 79
nextBoolean(double p) for Random class 3 40
iterator/ListIterator approach 17 25
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

776 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