protected Account safelyRetrieveAccountForId(long anAccountId) throws AccountNotFoundException {
        Account account = null;
        synchronized (accounts) {
            account = accountsById.get(anAccountId);
        }

        if (account == null) {
            throw new AccountNotFoundException("No account found for the id " + anAccountId);
        }

        LOGGER.info("Retrieved account " + account);
        return account;
    }
Internal method that safely (concurrency-wise) retrieves an account from the id passed in.

@param anAccountId The identifier of the account to retrieve.
@return The account instance retrieved.
@throws AccountNotFoundException If no account is found for the provided identifier.
samples/aspectj/src/main/java/org/apache/shiro/samples/aspectj/bank/SecureBankService.java