• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization with JavaBeans  RSS feed

 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having an issue with JavaBean synchronization. My java beans have all public methods marked as synchronized, and I have all the fields in my bean class as private. I have a default no arguement constructor. This bean is used by my servlets to store data temporarily. The issue is that if two people log in concurrently to the same set of servlets, and start entering data, the person that started first- their data will persist for both their own session, as well as the other person's session. I was not sure where to classify this, so I'm also including it in the servlets forum. Thanks for any help!
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ignore the above request for help- I was declaring my fields as static-minor oversight. Thanks anyway.
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew:
Read at the J2EE specification that you can not declare synchronized methods, that�s part of the container job. There are some limitations at Java Beans development, one of them is that you cannot use synchronization.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hadn't read the specification. I guess I was applying more of a general thought about java beans to my servlet environment- as I know that in Bruce Eckel's book, Thinking in Java, he discusses the need to synchronize methods when using java beans(in chapter 14- Multiple Threads). The reason for this, is that you have to assume that you are going to be using it in a multi-threaded environment. Now his context was more in terms of GUI development(using swing), not a Servlet environment. Thank you for clarifying for me.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!