public boolean hasLateTransaction(long currentTimeMs) {
        long lastTimestamp = oldestTxnLastTimestamp;
        return lastTimestamp > 0 && (currentTimeMs - lastTimestamp) > maxTransactionTimeoutMs + ProducerStateManager.LATE_TRANSACTION_BUFFER_MS;
    }
This method checks whether there is a late transaction in a thread safe manner.
storage/src/main/java/org/apache/kafka/storage/internals/log/ProducerStateManager.java