Two stage termination mode

Time:2021-9-4

Two stage termination mode

Two-Phase Termination Patter

Description: enables the monitoring thread to gracefully terminate other running worker threads

Code implementation:

class TwoPhaseTermination {

Test code:

public class TwoPhaseTerminationTest {

    public static void main(String[] args) {

        TwoPhaseTermination pattern = new TwoPhaseTermination();
        pattern.start();

        try {
            TimeUnit.SECONDS.sleep(2);
            pattern.stop();
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Operation results:

Two stage termination mode

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]