Backend Development 5 min read

Implementing Gender-Based Rest Periods in a Supermarket Checkout Simulation (Third Round)

The article describes how a Java-based supermarket checkout performance test was refined by adding gender-specific rest intervals—2 minutes for male cashiers and 5 minutes for female cashiers—through code changes that introduce a gender attribute, rest logic, and integration into the test workflow.

FunTester
FunTester
FunTester
Implementing Gender-Based Rest Periods in a Supermarket Checkout Simulation (Third Round)

After sending the latest test report to the cashiers, they complained that the test intensity was too high and requested additional rest periods during their shifts.

A cashier proposed adding a rest stage: if a cashier works continuously for more than 30 minutes, they should rest for 2 minutes, but this was challenged because it only considered male cashiers, while female cashiers needed at least 5 minutes of rest.

Following an open discussion, the rule was adopted: male cashiers rest 2 minutes after 30 minutes of work, female cashiers rest 5 minutes; the supermarket has 2 male and 6 female cashiers.

The test case was updated with two main changes: add a gender attribute with corresponding rest time, and add a rest stage to implement the rest functionality.

/**
 * 性别,1:男,2:女
 */
public int sex;

/**
 * 单次休息时间,单位分钟
 * 男性员工:2分钟;女性员工5分钟
 */
public int restTime;

/**
 * 最大工作时间,单位分钟
 */
public int maxWorkTime;

/**
 * 上一次开始工作时间,毫秒时间戳
 */
public long lastStartWorkTime;

The constructor was modified to initialize these new fields.

/**
 * 构造方法
 * @param totalNum 执行的总次数
 * @param sex 性别
 */
public SupermarketCheckoutTaskThird(int totalNum, int sex) {
    this.totalNum = totalNum; // 设置执行的总次数
    this.costTime = new ArrayList<>(totalNum); // 初始化耗时收集集合类容量
    this.sex = sex; // 设置性别
    this.maxWorkTime = 30; // 设置最大工作时间
    this.restTime = sex == 1 ? 2 : 5; // 设置单次休息时间
    priceCostTime = new AtomicLong(); // 初始化计价耗时统计
    payCostTime = new AtomicLong(); // 初始化支付耗时统计
    packCostTime = new AtomicLong(); // 初始化打包耗时统计
}

The before() method records the start time of the latest work period.

@Override
public void before() {
    super.before();
    lastStartWorkTime = System.currentTimeMillis(); // 设置开始工作时间
}

The rest() method checks if the elapsed work time exceeds the maximum and, if so, pauses execution for the appropriate rest duration and updates the start time.

/**
 * 休息
 */
public void rest() {
    long timeMillis = System.currentTimeMillis(); // 当前时间
    if (timeMillis - lastStartWorkTime > maxWorkTime * 60 * 1000) {
        ThreadTool.sleep(restTime * 60 * 1000); // 休息
        lastStartWorkTime = System.currentTimeMillis(); // 设置开始工作时间
    }
}

Finally, the rest() method is embedded into the test() method to ensure cashiers take breaks at the appropriate times during the test.

This improvement not only refines the test case but also demonstrates a human‑centered approach, emphasizing that technical performance testing should consider employee well‑being to achieve both efficiency and humane outcomes.

Book reference: From Java to Performance Testing . The author invites readers to support the work through appreciation donations, offering early access to unpublished chapters and video tutorials.

backendjavaPerformance TestingMultithreadinghuman‑centered designRest Scheduling
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.