How to prevent repeated requests when performing a time-consuming job operation in play framework 1?

perform a time-consuming job operation in play1 to prevent repeated requests for Cache.set (order.id, true) in job to execute code Cache.delete (order.id);

    if (Cache.get(order.id)!=null) {
        fail("");
    }

is this feasible? The server doesn"t seem to work. Local testing can be

.
Apr.06,2021

can be written asynchronously, such as CompletableFuture.runAsync () , and then declare a volatile boolean variable control state to identify whether the task is executing, such as

volatile boolean flag = false;

void func(){
    if (!flag) {
        CompletableFuture.runAsync(() -> {
            try {
                flag = true;
                doWork();
            } finally {
                flag = false;
            }
        });
    } else {
        failWork();
    }
}
Menu