Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sharing info between servlets

 
satyam pat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How often does this information change and what changes it?

Bill
 
satyam pat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64852
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
satyam pat
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64852
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static depends upon class loaders which can be complicated in web apps. Application context is the preferred location.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic