aspose file tools*
The moose likes Servlets and the fly likes sharing info between servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sharing info between servlets" Watch "sharing info between servlets" New topic
Author

sharing info between servlets

satyam pat
Greenhorn

Joined: Apr 16, 2011
Posts: 14
Hello all,

I have a small web application where I need to share some information(some background update status) between servlets.

I am currently putting that information in static synchronized map in my constant class.

Does this approach any drawback ?

Thanks

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
How often does this information change and what changes it?

Bill
satyam pat
Greenhorn

Joined: Apr 16, 2011
Posts: 14
On application startup, there is need of syncing ldap server(with latest ldifs).
This sync process is initiated through one of servlets.

While sync is in progress I want all requests by other servlets (which are dependent on sync completion job) route to maintenance page.
Currently I put the sync status in map which gets updated by sync servlet.

Other servlets check for sync status before servicing requests.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Why bother with all that? Just perform the action in a context listener which is guaranteed to execute prior to any servlets getting activated.

And I'd put shared info in the application context rather than static data.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
satyam pat
Greenhorn

Joined: Apr 16, 2011
Posts: 14
Thanks for the thoughts.

But i still don't see the real benefit of using applicatin context to keep that information as against static data.

I have few utitility classes/servlets which use that information and static data seems to be feasible way.

PS: Also not all the servlets needs to wait for sync completion.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Static depends upon class loaders which can be complicated in web apps. Application context is the preferred location.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sharing info between servlets