0

I am using apache-tomcat-7.0.35 as web server for my java web application.
I am confused what is difference between two methods of storing object as given below.

1.store object in ApplicationContext
2.declare private static final <Type> obj = new <Type>(); and access it.

Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82

2 Answers2

2

I think the main difference here is that if your object is in the ApplicationContext, then there's some container managing it's lifecycle explicitly. So you can take advantage of container lifecycle events and perform actions after creation and before destruction for example.

Leo
  • 6,480
  • 4
  • 37
  • 52
0

To put it simply: Static members are available to all aspects of your program, ApplicationContext members are only available to members that have have access to the ServletContext.

There is more to this underneath though

RossBille
  • 1,448
  • 1
  • 17
  • 26