Skip to content

It is recommended to use ConcurrentHashMap instead of synchronous Has… #1405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public class LimitedAgeDiskCache extends BaseDiskCache {

private final long maxFileAge;

private final Map<File, Long> loadingDates = Collections.synchronizedMap(new HashMap<File, Long>());

private final ConcurrentHashMap<File, Long> loadingDates = new ConcurrentHashMap<>();
/**
* @param cacheDir Directory for file caching
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.lang.ref.Reference;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
* Base memory cache. Implements common functionality for memory cache. Provides object references (
Expand All @@ -30,7 +31,7 @@
public abstract class BaseMemoryCache implements MemoryCache {

/** Stores not strong references to objects */
private final Map<String, Reference<Bitmap>> softMap = Collections.synchronizedMap(new HashMap<String, Reference<Bitmap>>());
private final ConcurrentHashMap<String, Reference<Bitmap>> softMap = = new ConcurrentHashMap<>();

@Override
public Bitmap get(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
* Limited {@link Bitmap bitmap} cache. Provides {@link Bitmap bitmaps} storing. Size of all stored bitmaps will not to
Expand All @@ -43,7 +44,7 @@ public class LargestLimitedMemoryCache extends LimitedMemoryCache {
* size will exceed limit then object with the largest size is deleted (but it continue exist at
* {@link #softMap} and can be collected by GC at any time)
*/
private final Map<Bitmap, Integer> valueSizes = Collections.synchronizedMap(new HashMap<Bitmap, Integer>());
private final ConcurrentHashMap<Bitmap, Integer> valueSizes = new ConcurrentHashMap<>();

public LargestLimitedMemoryCache(int sizeLimit) {
super(sizeLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Decorator for {@link MemoryCache}. Provides special feature for cache: if some cached object age exceeds defined
Expand All @@ -37,7 +38,7 @@ public class LimitedAgeMemoryCache implements MemoryCache {
private final MemoryCache cache;

private final long maxAge;
private final Map<String, Long> loadingDates = Collections.synchronizedMap(new HashMap<String, Long>());
private final ConcurrentHashMap<String, Long> loadingDates = new ConcurrentHashMap<>();

/**
* @param cache Wrapped memory cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import java.util.concurrent.ConcurrentHashMap;
/**
* Limited {@link Bitmap bitmap} cache. Provides {@link Bitmap bitmaps} storing. Size of all stored bitmaps will not to
* exceed size limit. When cache reaches limit size then the bitmap which used the least frequently is deleted from
Expand All @@ -43,7 +43,7 @@ public class UsingFreqLimitedMemoryCache extends LimitedMemoryCache {
* size will exceed limit then object with the least frequently usage is deleted (but it continue exist at
* {@link #softMap} and can be collected by GC at any time)
*/
private final Map<Bitmap, Integer> usingCounts = Collections.synchronizedMap(new HashMap<Bitmap, Integer>());
private final ConcurrentHashMap<Bitmap, Integer> usingCounts = new ConcurrentHashMap<>();

public UsingFreqLimitedMemoryCache(int sizeLimit) {
super(sizeLimit);
Expand Down