• Post Reply Bookmark Topic Watch Topic
  • New Topic

synchronize these methods ?  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
Hi all.
I am creating a small forum web application.
to access the database, I am using a class that is used to insert/get data from the database.
consider it like a DAO.
my question is, since the servlet will be used by a large number of users, should I declare the method of my DAO with synchronized keyword or relay on the database isolation policy ?
thanks.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37253
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
You don't need to synchronize the calls yourself. All database calls operate inside of a transaction. The database will ensure consistency.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
but I have been reading some tutorials that creates such a class for accessing the database and synchronized the methods because the whole web application will use this class.
this application creates one instance of this class and puts it in the application scope.
in this case, synchronization is and issue right ??
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37253
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Yes. In that case the synchronized methods are protecting the connection object itself. It is better to use a connection pool (provided by the application server) than manage your own connections. Even if you must manage the connection yourself, it should be in a separate class. The rest of the database code doesn't need to be synchronized.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!