Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
3096888c
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3096888c
编写于
7月 05, 2016
作者:
S
Stephane Nicoll
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better synchronization in ConcurrentMapCache
Issue: SPR-13810
上级
9b9f3714
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
22 deletion
+16
-22
spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java
.../springframework/cache/concurrent/ConcurrentMapCache.java
+5
-11
spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheTests.java
...ngframework/cache/concurrent/ConcurrentMapCacheTests.java
+11
-11
未找到文件。
spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java
浏览文件 @
3096888c
...
@@ -59,7 +59,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
...
@@ -59,7 +59,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
* @param name the name of the cache
* @param name the name of the cache
*/
*/
public
ConcurrentMapCache
(
String
name
)
{
public
ConcurrentMapCache
(
String
name
)
{
this
(
name
,
new
ConcurrentHashMap
<
Object
,
Object
>(
256
),
true
);
this
(
name
,
new
ConcurrentHashMap
<>(
256
),
true
);
}
}
/**
/**
...
@@ -69,7 +69,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
...
@@ -69,7 +69,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
* values for this cache
* values for this cache
*/
*/
public
ConcurrentMapCache
(
String
name
,
boolean
allowNullValues
)
{
public
ConcurrentMapCache
(
String
name
,
boolean
allowNullValues
)
{
this
(
name
,
new
ConcurrentHashMap
<
Object
,
Object
>(
256
),
allowNullValues
);
this
(
name
,
new
ConcurrentHashMap
<>(
256
),
allowNullValues
);
}
}
/**
/**
...
@@ -141,20 +141,14 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
...
@@ -141,20 +141,14 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
return
(
T
)
get
(
key
).
get
();
return
(
T
)
get
(
key
).
get
();
}
}
else
{
else
{
synchronized
(
this
.
store
)
{
return
(
T
)
fromStoreValue
(
this
.
store
.
computeIfAbsent
(
key
,
r
->
{
if
(
this
.
store
.
containsKey
(
key
))
{
return
(
T
)
get
(
key
).
get
();
}
T
value
;
try
{
try
{
value
=
valueLoader
.
call
(
);
return
toStoreValue
(
valueLoader
.
call
()
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
throw
new
ValueRetrievalException
(
key
,
valueLoader
,
ex
);
throw
new
ValueRetrievalException
(
key
,
valueLoader
,
ex
);
}
}
put
(
key
,
value
);
}));
return
value
;
}
}
}
}
}
...
...
spring-context/src/test/java/org/springframework/cache/concurrent/ConcurrentMapCacheTests.java
浏览文件 @
3096888c
/*
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -44,9 +44,9 @@ public class ConcurrentMapCacheTests extends AbstractCacheTests<ConcurrentMapCac
...
@@ -44,9 +44,9 @@ public class ConcurrentMapCacheTests extends AbstractCacheTests<ConcurrentMapCac
@Before
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
nativeCache
=
new
ConcurrentHashMap
<
Object
,
Object
>();
this
.
nativeCache
=
new
ConcurrentHashMap
<
>();
cache
=
new
ConcurrentMapCache
(
CACHE_NAME
,
nativeCache
,
true
);
this
.
cache
=
new
ConcurrentMapCache
(
CACHE_NAME
,
this
.
nativeCache
,
true
);
cache
.
clear
();
this
.
cache
.
clear
();
}
}
@Override
@Override
...
@@ -84,9 +84,9 @@ public class ConcurrentMapCacheTests extends AbstractCacheTests<ConcurrentMapCac
...
@@ -84,9 +84,9 @@ public class ConcurrentMapCacheTests extends AbstractCacheTests<ConcurrentMapCac
public
void
testNonSerializableContent
()
{
public
void
testNonSerializableContent
()
{
ConcurrentMapCache
serializeCache
=
createCacheWithStoreByValue
();
ConcurrentMapCache
serializeCache
=
createCacheWithStoreByValue
();
thrown
.
expect
(
IllegalArgumentException
.
class
);
th
is
.
th
rown
.
expect
(
IllegalArgumentException
.
class
);
thrown
.
expectMessage
(
"Failed to serialize"
);
th
is
.
th
rown
.
expectMessage
(
"Failed to serialize"
);
thrown
.
expectMessage
(
this
.
cache
.
getClass
().
getName
());
th
is
.
th
rown
.
expectMessage
(
this
.
cache
.
getClass
().
getName
());
serializeCache
.
put
(
createRandomKey
(),
this
.
cache
);
serializeCache
.
put
(
createRandomKey
(),
this
.
cache
);
}
}
...
@@ -96,15 +96,15 @@ public class ConcurrentMapCacheTests extends AbstractCacheTests<ConcurrentMapCac
...
@@ -96,15 +96,15 @@ public class ConcurrentMapCacheTests extends AbstractCacheTests<ConcurrentMapCac
String
key
=
createRandomKey
();
String
key
=
createRandomKey
();
this
.
nativeCache
.
put
(
key
,
"Some garbage"
);
this
.
nativeCache
.
put
(
key
,
"Some garbage"
);
thrown
.
expect
(
IllegalArgumentException
.
class
);
th
is
.
th
rown
.
expect
(
IllegalArgumentException
.
class
);
thrown
.
expectMessage
(
"Failed to deserialize"
);
th
is
.
th
rown
.
expectMessage
(
"Failed to deserialize"
);
thrown
.
expectMessage
(
"Some garbage"
);
th
is
.
th
rown
.
expectMessage
(
"Some garbage"
);
serializeCache
.
get
(
key
);
serializeCache
.
get
(
key
);
}
}
private
ConcurrentMapCache
createCacheWithStoreByValue
()
{
private
ConcurrentMapCache
createCacheWithStoreByValue
()
{
return
new
ConcurrentMapCache
(
CACHE_NAME
,
nativeCache
,
true
,
return
new
ConcurrentMapCache
(
CACHE_NAME
,
this
.
nativeCache
,
true
,
new
SerializationDelegate
(
ConcurrentMapCacheTests
.
class
.
getClassLoader
()));
new
SerializationDelegate
(
ConcurrentMapCacheTests
.
class
.
getClassLoader
()));
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录