有个问题一直没有找到答案,在Jive2。6中的 DBForum.java里, 有如下更新数据库的方法:
/**
* Saves forum data to the database.
*/
private synchronized void saveToDb() {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = ConnectionManager.getConnection();
pstmt = con.prepareStatement(SAVE_FORUM);
pstmt.setString(1, name);
pstmt.setString(2, description);
pstmt.setInt(3, modDefaultThreadValue);
pstmt.setInt(4, modDefaultMessageValue);
pstmt.setInt(5, modMinThreadValue);
pstmt.setInt(6, modMinMessageValue);
pstmt.setString(7, StringUtils.dateToMillis(creationDate));
pstmt.setString(8, StringUtils.dateToMillis(modifiedDate));
pstmt.setLong(9, id);
pstmt.executeUpdate();
}
catch( SQLException sqle ) {
sqle.printStackTrace();
}
finally {
try { pstmt.close(); }
catch (Exception e) { e.printStackTrace(); }
try { con.close(); }
catch (Exception e) { e.printStackTrace(); }
}
// Re-add forum to cache.
factory.cacheManager.forumCache.put(new Long(this.id), this);
}
我的问题是:对于这样的方法,有必要同步么? 为什么要同步?