• Post Reply Bookmark Topic Watch Topic
  • New Topic

object in context v/s static object

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In web environment, I want one object to be access from everywhere so I put it into context. If I make it static and access it from class name wherever I wnat to access then what difference it would make??

Please comment...

Thanks a lot.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you place it in the context it will be lost but can be recreated each time the context is reloaded. The down side it that you can't enforce it's immutability - anyone that can see it can update it.

Depending on your setup, making it globally available (eg like a singleton) may not refresh with context restarts (don't confuse this with server restarts, you can often drop and restart a context without restarting the server). While this sounds OK, it isn't really a good design and can cause other unforseen ussues down the road.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David.

But there must be some loss if we put object into context...
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you intend to use the data in the jsps, then all that beautiful scoped EL lookup in jstl or the useBean isnt going to work.

cheers,
ram.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!