It's not necessary to acquire all locks before closing the database,

since Database.close() prevents new transactions from starting anyway.
This commit is contained in:
akwizgran
2011-08-05 13:39:49 +01:00
parent c2045296eb
commit 18654f1514
3 changed files with 4 additions and 47 deletions

View File

@@ -48,9 +48,8 @@ interface Database<T> {
void open(boolean resume) throws DbException;
/**
* Waits for all open transactions to finish and closes the database.
* <p>
* Locking: all locks write.
* Prevents new transactions from starting, waits for all current
* transactions to finish, and closes the database.
*/
void close() throws DbException;

View File

@@ -97,37 +97,7 @@ class ReadWriteLockDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
public void close() throws DbException {
cleaner.stopCleaning();
contactLock.writeLock().lock();
try {
messageLock.writeLock().lock();
try {
messageStatusLock.writeLock().lock();
try {
ratingLock.writeLock().lock();
try {
subscriptionLock.writeLock().lock();
try {
transportLock.writeLock().lock();
try {
db.close();
} finally {
transportLock.writeLock().unlock();
}
} finally {
subscriptionLock.writeLock().unlock();
}
} finally {
ratingLock.writeLock().unlock();
}
} finally {
messageStatusLock.writeLock().unlock();
}
} finally {
messageLock.writeLock().unlock();
}
} finally {
contactLock.writeLock().unlock();
}
db.close();
}
public ContactId addContact(Map<String, Map<String, String>> transports)

View File

@@ -81,19 +81,7 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
public void close() throws DbException {
cleaner.stopCleaning();
synchronized(contactLock) {
synchronized(messageLock) {
synchronized(messageStatusLock) {
synchronized(ratingLock) {
synchronized(subscriptionLock) {
synchronized(transportLock) {
db.close();
}
}
}
}
}
}
db.close();
}
public ContactId addContact(Map<String, Map<String, String>> transports)