@@ -0,0 +1,1539 @@
+/*%0A    Java Libraries https://github.com/foilen/java-libraries%0A    Copyright (c) 2015-2018 Foilen (http://foilen.com)%0A%0A    The MIT License%0A    http://opensource.org/licenses/MIT%0A%0A */%0Apackage com.foilen.smalltools.tools;%0A%0Aimport java.util.concurrent.atomic.AtomicBoolean;%0A%0A/**%0A * To be able to execute some commands periodically while a main action is running.%0A */%0Apublic class HeartbeatTools extends AbstractBasics %7B%0A%0A    /**%0A     * Execute the main action and execute in another thread the ping action continuously.%0A     *%0A     * @param timeBetweenPingsInMs%0A     *            the time before the first ping and between them%0A     * @param pingAction%0A     *            the action to execute frequently while the mainAction is running%0A     * @param mainAction%0A     *            the main action to execute%0A     */%0A    public static void execute(long timeBetweenPingsInMs, Runnable pingAction, Runnable mainAction) %7B%0A%0A        // Start the pinging thread%0A        AtomicBoolean keepPinging = new AtomicBoolean(true);%0A        Thread thread = new Thread(() -%3E %7B%0A%0A            while (keepPinging.get()) %7B%0A                ThreadTools.sleep(timeBetweenPingsInMs);%0A                if (keepPinging.get()) %7B%0A                    pingAction.run();%0A                %7D%0A            %7D%0A%0A        %7D, HeartbeatTools.class.getSimpleName());%0A        thread.setDaemon(true);%0A        thread.start();%0A%0A        // Execute the main%0A        try %7B%0A            mainAction.run();%0A        %7D finally %7B%0A            // Stop%0A            keepPinging.set(false);%0A        %7D%0A%0A    %7D%0A%0A%7D%0A

Add HeartbeatTools