设为首页 加入收藏

TOP

Azkaban源码阅读之CachingFlowManager (一)
2014-11-24 11:57:11 】 浏览:470
Tags:Azkaban 源码 阅读 CachingFlowManager

CachingFlowManager这部分为Azkaban在管理job中cache管理这一部分。

[java] 、
public CachingFlowManager(FlowManager baseManager, final int cacheSize)
{
this.baseManager = baseManager;

this.flowCache = Collections.synchronizedMap(
new LinkedHashMap((int) (cacheSize * 1.5), 0.75f, true){
@Override
protected boolean removeEldestEntry(Map.Entry eldest)
{
final boolean tooManyElements = super.size() > cacheSize;

if (tooManyElements) {
final Status status = eldest.getValue().getFlow().getStatus();

if (status != Status.RUNNING) {
return true;
}
else {
log.warn(String.format(
"Cache is at size[%s] and should have evicted an entry, but the oldest entry wasn't completed[%s]. Perhaps the cache size is too small",
super.size(),
status
));
}
}

return false;
}
}
);
}

public CachingFlowManager(FlowManager baseManager, final int cacheSize)
{
this.baseManager = baseManager;

this.flowCache = Collections.synchronizedMap(
new LinkedHashMap((int) (cacheSize * 1.5), 0.75f, true){
@Override
protected boolean removeEldestEntry(Map.Entry eldest)
{
final boolean tooManyElements = super.size() > cacheSize;

if (tooManyElements) {
final Status status = eldest.getValue().getFlow().getStatus();

if (status != Status.RUNNING) {
return true;
}
else {
log.warn(String.format(
"Cache is at size[%s] and should have evicted an entry, but the oldest entry wasn't completed[%s]. Perhaps the cache size is too small",
super.size(),
status
));
}
}

return false;
}
}
);
}

在这个方法中涉及到几个地方是之前没有学习到过、也没有遇到过的。

下面都一一来研究下。

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

1、Collections.synchronizedMap

先来看下在JDK中对Collections的解释:

\

接下来synchronizedMap

顾名思义,synchronize是同步,那则为同步的map。

public static Map synchronizedMap(Map m) 这是一个返回由指定映射支持的同步(线程安全的)映射的方法。也就是返回一个线程安全的map

2、new LinkedHashMap((int) (cacheSize * 1.5), 0.75f, true)

LinkedHashMap是JDK1.4引入的新的集合类,相信很多人都没有用到过LinkedHashMap。

LinkedHashMap相当于是一个对HashMap的扩展,它在Hash的实现有加上了对Linked的支持。

在我们平常使用的时候几乎所有情况下都会使用这些集合类无参的构造方

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇黑马程序员-java基础学习集合总结.. 下一篇Java中的instanceof关键字

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目