• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Troubles

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops, sorry about that. I guess I hit 'Post' in the wrong window.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. You're in the right place now.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic