• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Troubles

 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty new to threads in Java. I'm currently building a medium sized tool and for some reason I thought JavaBeans handled multiple threads... definitely not the case. I tested the tool on two difference machines at the same time and had them editing each others data -- not good.


So here's the extremely simplied layout of my code (ignore syntax errors):


Each listData must be entirely unique to each user (ie: a new listData should be created for each user) and the data should never be viewable by another user (it's not personal information or anything important).

How shoud I go about this? Any help would be much appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The definition of the bean is irrelevant. What matters is how you are using it.

Are you perhaps storing it as an instance variable in a servlet? If so, that's the problem.
 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Are you perhaps storing it as an instance variable in a servlet? If so, that's the problem.


The only place I can think I might be "instantiating" it anywhere is in the faces-config.xml file.
I have the bean in there and call it from a number of different .jsp pages (ex: "Your data is: DataBean.viewData")

Is this the idea you're referring to?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have mentioned that you are using JSF right off the bat. Moved to the JSF forum.
 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops, sorry about that. I guess I hit 'Post' in the wrong window.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem. You're in the right place now.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF beans are POJOs - generic JavaBeans. JavaBeans are simply Java classes treated as components, with certain conventions applied. If you want thread-safe, you have to provide it yourself as/where needed. The price of ultimate flexibility while retaining ultimate efficiency.
 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:If you want thread-safe, you have to provide it yourself as/where needed.

Alright, so how would I provide it myself?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Charles Swanson wrote:
Tim Holloway wrote:If you want thread-safe, you have to provide it yourself as/where needed.

Alright, so how would I provide it myself?


Basic Java. The magic word is "synchronized".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic