Branch: refs/heads/master
Home:
https://github.com/forge/core
Commit: 756c0b9c4af3bb8cf3d401bd4afac5ccb8f8cd93
https://github.com/forge/core/commit/756c0b9c4af3bb8cf3d401bd4afac5ccb8f8...
Author: George Gastaldi <gegastaldi(a)gmail.com>
Date: 2014-03-05 (Wed, 05 Mar 2014)
Changed paths:
M
projects/impl/src/main/java/org/jboss/forge/addon/projects/impl/InMemoryProjectCache.java
Log Message:
-----------
Using WeakHashMap instead of a ConcurrentHashMap.
The following test proves that elements are garbage collected correctly
with WeakHashMap:
public void testWeakHashMap() throws Exception
{
final Map<String, WeakReference<String>> projects = new
ConcurrentHashMap<>();
final Map<String, String> projectsWeak = new WeakHashMap<>();
ExecutorService pool = Executors.newCachedThreadPool();
for (int i = 0; i < 100; i++)
{
final String idx = String.valueOf(i);
pool.execute(new Runnable()
{
@Override
public void run()
{
projects.put(String.valueOf(idx), new
WeakReference<String>(new String(idx)));
projectsWeak.put(String.valueOf(idx), new String(idx));
}
});
}
System.gc();
Thread.sleep(5000);
Assert.assertTrue(projectsWeak.size() < projects.size());
}