Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
adam cooper
Greenhorn
Posts: 2
1
  • Mark post as helpful
  • send pies
  • 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!

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gave you a cow for actually trying it out and verifying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic