• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about thread safety  RSS feed

 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a collection of objects in my JSP application that are shared among all users as read-only data. The request code in the Controller servlet looks like this:


The BeanStorage is a singleton. It contains a Vector, in which the ItemClass objects are stored. However, I am not sure if this code is thread-safe.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the data is read-only, what problems might arise?

P.S. Rather than use a singleton for such data, I store an instance of the object in application context.
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion my code is ok, because the bean objects are stored in a Vector object, which is synchronized anyway (http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Vector.html), but generally I am quite uncertain about which parts
of the code should be synchronized or not, because I don't how how to simulate a lot of requests to my application on my local machine. Is there a way to stress-test a jsp application?



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You never answered my question.
Bear Bibeault wrote:If the data is read-only, what problems might arise?
 
Daniel Zuckermann
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read-only operations shouldn't cause any problems.

That's the article that made me question my code: http://blogs.msdn.com/b/ericlippert/archive/2011/05/23/read-only-and-threadsafe-are-different.aspx
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!