wood burning stoves*
The moose likes JForum and the fly likes How does JForum make sure there will be no two users with same name inserted into the database? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JForum
Bookmark "How does JForum make sure there will be no two users with same name inserted into the database?" Watch "How does JForum make sure there will be no two users with same name inserted into the database?" New topic
Author

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

adam cooper
Greenhorn

Joined: Aug 14, 2013
Posts: 2
    
    1
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30146
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
adam cooper
Greenhorn

Joined: Aug 14, 2013
Posts: 2
    
    1
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30146
    
150

I gave you a cow for actually trying it out and verifying.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does JForum make sure there will be no two users with same name inserted into the database?
 
Similar Threads
Table Lock
Problem in composite key as foreign key mapping w/ hibernate v3.2.6 and jdk-6
implements LoginAuthenticator
Connection with an external user database
Inserting multiple checkbox values into a table