Code example for AtomicReference

Methods: set

0
 
    static <T> Future<T> initiateAndDie(final Task<T> task) {
        final AtomicReference<Future<T>> result = new AtomicReference<Future<T>>();
        Runnable r = new Runnable() {
            public void run() { 
                result.set(task.run());
            } 
        }; 
        Thread t = new Thread(r);
        t.start();
        while (t.isAlive()) {
            try { 
                t.join();
            } catch (InterruptedException x) {
            } 
        } 
        return result.get();
    } 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE