wood burning stoves 2.0*
The moose likes Servlets and the fly likes Context Listener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Context Listener" Watch "Context Listener" New topic
Author

Context Listener

Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

How can we use context listener in real-time applications.

Regards,
Neeraj.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Does your app have anything that needs to be initialized at startup?
Does it have anything that needs to be cleaned up at shutdown?
If so, a ContextListener is just the thing for you.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi Ben,

Thanx for the reply...I justed wanted for improving my knowledge.

Can u provide some scenario, where u have used context-listner. In books I have read for db connections etc. but not satisfied with them..

Regards,
Neeraj.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

True not too many people would make a DB connection in a listener.

It would make sense, however to initialize a connection pool from a listener.
You may also have initialization data that is stored in a database that you want to retrieve and cache when the context initializes.

I have a webservice app that communicates with a non-browser application.
In it there is a login handshake that gives the client an ID string (similar to a JSPSessionID). I have an in-memory object that keeps track of who's logged in and when their session expires. So that I can restart the application without throwing all of these clients out, I serialize that object to disk when the context is destroyed and de-serialize it when the context starts back up.
Neeraj Vij
Ranch Hand

Joined: Nov 25, 2003
Posts: 315
Hi,

thnx Ben for all your inputs.

Regards,
Neeraj.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Context Listener
 
Similar Threads
How to run code on server startup?
How to load file at the time of start of the application
Intercepting TomCat 5
? for web-applications
Loading common web objects on startup