⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preloader.java

📁 java concurrency in practice 源码. JAVA并发设计
💻 JAVA
字号:
package net.jcip.examples;import java.util.concurrent.*;/** * Preloader * * Using FutureTask to preload data that is needed later * * @author Brian Goetz and Tim Peierls */public class Preloader {    ProductInfo loadProductInfo() throws DataLoadException {        return null;    }    private final FutureTask<ProductInfo> future =        new FutureTask<ProductInfo>(new Callable<ProductInfo>() {            public ProductInfo call() throws DataLoadException {                return loadProductInfo();            }        });    private final Thread thread = new Thread(future);    public void start() { thread.start(); }    public ProductInfo get()            throws DataLoadException, InterruptedException {        try {            return future.get();        } catch (ExecutionException e) {            Throwable cause = e.getCause();            if (cause instanceof DataLoadException)                throw (DataLoadException) cause;            else                throw LaunderThrowable.launderThrowable(cause);        }    }    interface ProductInfo {    }}class DataLoadException extends Exception { }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -