• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How does JForum make sure there will be no two users with same name inserted into the database?

 
Greenhorn
Posts: 2
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm reading the source code of JForum v2.x.x from http://jforum.net/.

I see that in the class UserAction, there is a call to dao.isUsernameRegistered(username) to check the name first before inserting a new user into the table. But, as far as I know, JForum runs in a multithread environment. What if when two different threads check if there is such a user with the name, say 'adam', in the table at the same time, and they both get false as the answer, and then they both insert a new user with 'adam' as name into the table JFORUM_USERS? How does JForum prevent this kind of thing from happening?

Thanks in advance!

 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adam,
Welcome to CodeRanch!

I was all set to say that there is a database constraint on that column forcing uniqueness, but there doesn't appear to be one.

In which case, I think they are counting on the odds of two people registering with the same id within a few seconds of each other is pretty slim.
 
adam cooper
Greenhorn
Posts: 2
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,

Thank you very much for your welcome and prompt reply!

You are completely right, and I even successfuly added two users with the same name by setting an appropriate breakpoint in the code.

Thanks again! ^_^
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I gave you a cow for actually trying it out and verifying.
 
Whatever you say buddy! And I believe this tiny ad too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic