Skip to content

Commit

Permalink
pinpoint-apm#2259 Fix potential thread safe problem in InterceptorScope
Browse files Browse the repository at this point in the history
 - Remove unnecessary API
  • Loading branch information
emeroad committed Nov 18, 2016
1 parent ca24c05 commit cb1a25e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ public V get(K key) {
throw new IllegalArgumentException("key must not be null");
}

return pool.get(key);
}

@Override
public V add(K key) {
if (key == null) {
throw new IllegalArgumentException("name must not be null");
}

final V alreadyExist = this.pool.get(key);
if (alreadyExist != null) {
return alreadyExist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ public interface Pool<K, V> {

V get(K key);

V add(K key);

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ public InterceptorScope getInterceptorScope(String name) {
throw new NullPointerException("name must not be null");
}

return interceptorScopePool.add(name);
return interceptorScopePool.get(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public void testConcurrentPool() throws Exception {

final String OBJECT_NAME = "test";

Assert.assertNull(pool.get(OBJECT_NAME));

InterceptorScope addedScope = pool.add(OBJECT_NAME);
InterceptorScope addedScope = pool.get(OBJECT_NAME);
Assert.assertSame(pool.get(OBJECT_NAME), addedScope);

InterceptorScope exist = pool.add(OBJECT_NAME);
InterceptorScope exist = pool.get(OBJECT_NAME);
Assert.assertSame(exist, addedScope);

InterceptorScope another = pool.get("another");
Assert.assertNotSame(exist, another);
}

}

0 comments on commit cb1a25e

Please sign in to comment.