3

I need to maintain a list of objects in a web application. This list can be viewed or modified (items added or deleted) by any user of the web application. There are chances that many users are accessing (modifying) the list almost at the same time. Which is the right approach to share the list. I can think of 2 ways.

  1. Static variable
  2. ServletContext

Please let me know which one is right and why. Also, please let me know if there is any other better way.

EDIT Issue is sharing objects between different users of application.

Prabhat
  • 2,261
  • 7
  • 46
  • 74
  • 1
    A database. That's what databases are for. And they will handle ACIDity for you. Anything you maintain in memory won't be accessible by another application instance running on another server. – JB Nizet Feb 21 '13 at 12:35
  • @JB Nizet : Many people accessing at the same time will put additional load on DB. There are other modules working with DB. So traffic will be high. – Prabhat Feb 21 '13 at 12:44
  • If you are using Jboss you could try a form of in-memory clustered cache Below link has more info http://docs.jboss.org/jbosscache/1.4.0/TreeCache/en/html/replication.html – anthonyms Feb 21 '13 at 12:54
  • @artfullyContrived : Looking for handling within application itself. – Prabhat Feb 21 '13 at 12:59
  • I don't understand your question. You seem to want to share data among several application instances, thus running in separate JVMs, but at the same time only want an in-memory solution within the application itself. Those two requirements are contradictory. – JB Nizet Feb 21 '13 at 13:01
  • @JB Nizet: By application instances, I mean, different users. Edited question. Sorry for confusion. – Prabhat Feb 21 '13 at 13:12

2 Answers2

1

Database if speed is not the most important factor. If you need speed some shared memory solution with locking is good. Such as Hazelcast http://www.hazelcast.com/

Dan
  • 407
  • 4
  • 16
0

You can use database, custom datasource (simple list wrapped by DataSource interface) and many more, but...

any instance of the web application

should it be any user of webapp, right?

Koziołek
  • 2,791
  • 1
  • 28
  • 48