Showing posts with label J2EE. Show all posts
Showing posts with label J2EE. Show all posts

Thursday, July 31, 2008

Updating the state of a Singleton Object after specific interval of time

I've created a Singleton Object which holds some values which are fetched from the database table. Following are the class specs:

1) All setter methods are private
2) All getter methods are public
3) One configuration method that sets all the values in the related attributes of class using their private setters

The need was to update the state of this singleton object when there are any changes made in the configuration table in the database. But to achieve this, I need to restart the server each time when any changes has been made in the configuration table.

So I created one WatchDog class in a thread that continuously changes the state of a singleton configuration object after a specific interval of time, & this time interval in-turn is fetched dynamically from the same configuration table from the database :)

Wednesday, June 18, 2008

Implemented "SessionListener"

Blogging after a long time :)

Today I implemented Session Listener in our Project. Actually our requirement was to do certain database clean-up after the session time-out takes place. We could have called a Struts action when user clicks on Logout button, but the problem was - if the user closes the browser directly or forcefully closes the browser through Windows Task Manager, then how to call the clean-up code, so there was a need such that this code gets run by the server automatically after the session is about to time-out.

So I wrote a SessionListener class that implements HttpSessionListener. It's really a very cool concept that keeps track of each & every users' session. Even if you close the client browser, the required clean-up code will be fired automatically by the server itself & there you'll also have the access of that respective session data for that particular user :)


Any comments are always welcome :)


_________________________________________________________________________________________________________________

"Look at the sky. We are not alone. The whole Universe is friendly to us and conspires only to give the best to those who dream and work."

- Dr. A P J Abdul Kalam
_________________________________________________________________________________________________________________