ISC2 Certified Secure Software Lifecycle Professional (CSSLP) Practice Question

During a peer review of a Java-based inventory microservice, you observe that two request-handling threads can call the following method at nearly the same time, which sometimes drives the shared in-memory stock counter below zero:

private static int stock = 10;

public void shipItem() {
    if (stock > 0) {
        stock--; // decrement
    }
}

Which secure coding modification best prevents this race condition while keeping the counter in memory?

  • Move the counter to a database table and rely on optimistic locking during updates.

  • Surround the if check and decrement in a synchronized block that locks on a private final object.

  • Declare the stock variable as volatile so every thread always reads the latest value before decrementing.

  • Increase the JVM heap size to minimize garbage-collection pauses that delay thread execution.

ISC2 Certified Secure Software Lifecycle Professional (CSSLP)
Secure Software Implementation
Your Score:
Settings & Objectives
Random Mixed
Questions are selected randomly from all chosen topics, with a preference for those you haven’t seen before. You may see several questions from the same objective or domain in a row.
Rotate by Objective
Questions cycle through each objective or domain in turn, helping you avoid long streaks of questions from the same area. You may see some repeat questions, but the distribution will be more balanced across topics.

Check or uncheck an objective to set which questions you will receive.

Bash, the Crucial Exams Chat Bot
AI Bot