Details
-
Improvement
-
Status: Resolved
-
Normal
-
Resolution: Fixed
-
None
-
None
Description
The DBManager class implements the singleton pattern using a Lock object, but it could replace the Lock object by declaring the instance() method as synchronized. Therefore, it avoids the race condition (as with Lock), but improves the readability and reduces the size of the method. Below is the new version of the method:
public static synchronized DBManager instance() throws IOException
{ if (dbMgr_ == null) dbMgr_ = new DBManager(); return dbMgr_; }