Updated nifty loading_screen

I went ahead and updated the loading_screen page to JDK 8 standard. Im not to this part of wiki yet so rest will have to wait a little longer.
https://jmonkeyengine.github.io/wiki/jme3/advanced/loading_screen.html

Notable changes,

Changed class TestLoadingScreen1 to use ExecutorService.

private ScheduledExecutorService exec = Executors.newScheduledThreadPool(2);

Removed

@Override
    public void stop() {
        super.stop();
        //the pool executor needs to be shut down so the application properly
        //exits.
        exec.shutdown();
    }

and added

@Override
    public void destroy() {
        super.destroy();
        shutdownAndAwaitTermination(exec);
    }

    //standard shutdown process for executor
    private void shutdownAndAwaitTermination(ExecutorService pool) {
        pool.shutdown(); // Disable new tasks from being submitted
        try {
            // Wait a while for existing tasks to terminate
            if (!pool.awaitTermination(6, TimeUnit.SECONDS)) {
                pool.shutdownNow(); // Cancel currently executing tasks
                // Wait a while for tasks to respond to being cancelled
                if (!pool.awaitTermination(6, TimeUnit.SECONDS)) {
                    LOG.log(Level.SEVERE, "Pool did not terminate {0}", pool);
                }
            }
        } catch (InterruptedException ie) {
            // (Re-)Cancel if current thread also interrupted
            pool.shutdownNow();
            // Preserve interrupt status
            Thread.currentThread().interrupt();
        }
    }

alt+F4 and X ing out of the app doesn’t call stop();

If anyone finds problems with the changes please let me know.

1 Like