• Post Reply Bookmark Topic Watch Topic
  • New Topic

should I synchronize this ?  RSS feed

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all.
I have a JSP page with some text fields and a form, when submitting this
form, the jsp will called a servlet to insert the text field's values into
a database.
inside this servlet , I have a method called createUser(....) , this method
is called within doPost method.
now, should I declare createUser( ) method with the synchronized keyword
to prevent the concurrent requests ?
thanks.
 
unni krishna
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do synchronization only if you encounter problems while accessing shared resource. For eg:- Application context is a shared resource. If your method just gets the parameter from request or session
object, then there is no need of synchronization.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about the databases ?
 
Celina Paul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think that any shared resource which should not have simultaneous access should be synchronized.

In your case, if this servlet can be accessed by n no. of users to create new users at the same time, then you should synchronize database access.

I would assume though that there would database row level loking while inserting...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!