aspose file tools*
The moose likes JSF and the fly likes Thread Troubles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Thread Troubles" Watch "Thread Troubles" New topic
Author

Thread Troubles

Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
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

Joined: Jan 10, 2002
Posts: 60059
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
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

Joined: Jan 10, 2002
Posts: 60059
    
  65

You should have mentioned that you are using JSF right off the bat. Moved to the JSF forum.
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
Whoops, sorry about that. I guess I hit 'Post' in the wrong window.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

No problem. You're in the right place now.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
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

Joined: Jun 25, 2001
Posts: 15641
    
  15

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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Troubles
 
Similar Threads
Problem accessing method defined in sub class
caching pages
Programming HTML content inside Custom Tag Handler
Issue in Struts Dropdown(Need Help Ranchers)
How to add icons along with the text in a JList[urgent]