aspose file tools
The moose likes Servlets and the fly likes object in context v/s static object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "object in context v/s static object" Watch "object in context v/s static object" New topic
Author

object in context v/s static object

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3829
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Oct 11, 2004
Posts: 3829
Thanks David.

But there must be some loss if we put object into context...
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: object in context v/s static object
 
Similar Threads
Cannot reference static method?
static method access to nonstatic method
how declare a variable global ?
Is x being accessed from a static context when using anonymous inner classes?
Static "this" reference / SwingWorker