Don't bother locking if there are no new transactions to process

This commit is contained in:
CalDescent 2022-01-30 19:50:09 +00:00
parent bd60c793be
commit 074bfadb28

View File

@ -1511,6 +1511,11 @@ public class Controller extends Thread {
} }
private void processIncomingTransactionsQueue() { private void processIncomingTransactionsQueue() {
if (this.incomingTransactions.size() == 0) {
// Don't bother locking if there are no new transactions to process
return;
}
try { try {
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock(); ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
if (!blockchainLock.tryLock(2, TimeUnit.SECONDS)) { if (!blockchainLock.tryLock(2, TimeUnit.SECONDS)) {
@ -1570,7 +1575,6 @@ public class Controller extends Thread {
LOGGER.error(String.format("Repository issue while processing incoming transactions", e)); LOGGER.error(String.format("Repository issue while processing incoming transactions", e));
} finally { } finally {
blockchainLock.unlock(); blockchainLock.unlock();
LOGGER.info("[processIncomingTransactionsQueue] Released blockchain lock");
} }
} }