Changeset 12811 in josm for trunk/src


Ignore:
Timestamp:
2017-09-10T00:48:43+02:00 (2 years ago)
Author:
bastiK
Message:

see #15277 - add hard reference to logger, else it gets garbage collected (findbugs warning)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r12765 r12811  
    4242public final class JCSCacheManager {
    4343    private static volatile CompositeCacheManager cacheManager;
    44     private static long maxObjectTTL = -1;
     44    private static final long maxObjectTTL = -1;
    4545    private static final String PREFERENCE_PREFIX = "jcs.cache";
    4646    public static final BooleanProperty USE_BLOCK_CACHE = new BooleanProperty(PREFERENCE_PREFIX + ".use_block_cache", true);
     
    5555    public static final IntegerProperty DEFAULT_MAX_OBJECTS_IN_MEMORY = new IntegerProperty(PREFERENCE_PREFIX + ".max_objects_in_memory", 1000);
    5656
    57     private JCSCacheManager() {
    58         // Hide implicit public constructor for utility classes
    59     }
    60 
    61     @SuppressWarnings("resource")
    62     private static void initialize() throws IOException {
    63         File cacheDir = new File(Main.pref.getCacheDirectory(), "jcs");
    64 
    65         if (!cacheDir.exists() && !cacheDir.mkdirs())
    66             throw new IOException("Cannot access cache directory");
    67 
    68         File cacheDirLockPath = new File(cacheDir, ".lock");
    69         if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
    70             Logging.warn("Cannot create cache dir lock file");
    71         }
    72         cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();
    73 
    74         if (cacheDirLock == null)
    75             Logging.warn("Cannot lock cache directory. Will not use disk cache");
    76 
     57    private static final Logger jcsLog;
     58
     59    static {
    7760        // raising logging level gives ~500x performance gain
    7861        // http://westsworld.dk/blog/2008/01/jcs-and-performance/
    79         final Logger jcsLog = Logger.getLogger("org.apache.commons.jcs");
     62        jcsLog = Logger.getLogger("org.apache.commons.jcs");
    8063        jcsLog.setLevel(Level.INFO);
    8164        jcsLog.setUseParentHandlers(false);
     
    11093            }
    11194        });
     95    };
     96
     97    private JCSCacheManager() {
     98        // Hide implicit public constructor for utility classes
     99    }
     100
     101    @SuppressWarnings("resource")
     102    private static void initialize() throws IOException {
     103        File cacheDir = new File(Main.pref.getCacheDirectory(), "jcs");
     104
     105        if (!cacheDir.exists() && !cacheDir.mkdirs())
     106            throw new IOException("Cannot access cache directory");
     107
     108        File cacheDirLockPath = new File(cacheDir, ".lock");
     109        if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
     110            Logging.warn("Cannot create cache dir lock file");
     111        }
     112        cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();
     113
     114        if (cacheDirLock == null)
     115            Logging.warn("Cannot lock cache directory. Will not use disk cache");
    112116
    113117        // this could be moved to external file
Note: See TracChangeset for help on using the changeset viewer.