amit surana
amit surana

Reputation: 49

How to keep a variable value same through out the application?

I am creating an application in which we can edit the content. Now this change in content should be visible to all. I was using a static variable for that. With that the content changes and change is visible to all but after sometime it again initialize to its initial value.

So can you give any suggestion through which I can maintain the change without using the database?

Upvotes: 0

Views: 646

Answers (2)

Kris
Kris

Reputation: 5792

I guess you can use Application Context available in JSP (example: http://www.java2s.com/Code/Java/JSP/ApplicationObject.htm) or you can try to keep a singleton class which maintains application level data and instialise it from within the init method of any servlet that is marked for loading at startup of the server.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240908

With that the content changes and change is visible to all but after sometime it again initialize to its initial value'

It happens only when your ClasLoader reloads the class containing static property.

You can go for FILE-IO(.xml, .properties) or DB,

Upvotes: 1

Related Questions