您的位置:首页 > 其它

单例模式示例

2015-12-23 09:48 344 查看
package pl.droidsonroids.gif;

import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
* Default executor for rendering tasks - {@link java.util.concurrent.ScheduledThreadPoolExecutor}
* with 1 worker thread and {@link java.util.concurrent.ThreadPoolExecutor.DiscardPolicy}.
*/
final class GifRenderingExecutor extends ScheduledThreadPoolExecutor {

private GifRenderingExecutor() {
super(1, new DiscardPolicy());
}

@SuppressWarnings("StaticNonFinalField") //double-checked singleton initialization
private static volatile GifRenderingExecutor instance = null;

public static GifRenderingExecutor getInstance() {
if (instance == null) {
synchronized (GifRenderingExecutor.class) {
if (instance == null) {
instance = new GifRenderingExecutor();
}
}
}
return instance;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: