Example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor.

Prototype

public ScheduledThreadPoolExecutor(int corePoolSize) 

Source Link

Document

Creates a new ScheduledThreadPoolExecutor with the given core pool size.

Usage

From source file:org.xflatdb.xflat.db.XFlatDatabase.java

/**
 * Initializes the database.  Once initialized the database can provide tables
 * and operate on underlying data./* w w  w .  j  av a  2 s .co  m*/
 * <p/>
 * The database will register a shutdown hook with the runtime to clean up any
 * resources and abandon all running tasks.  This shutdown hook will be removed
 * when {@link #shutdown() } is called.
 */
void initialize() {
    if (!this.state.compareAndSet(DatabaseState.Uninitialized, DatabaseState.Initializing)) {
        return;
    }

    try {
        String hello = String.format("Starting up XFlat database, version %s",
                org.xflatdb.xflat.Version.VERSION);
        if (org.xflatdb.xflat.Version.BUILD_REVISION > 0) {
            hello += String.format("\r\n        development revision %d (%s)",
                    org.xflatdb.xflat.Version.BUILD_REVISION,
                    org.xflatdb.xflat.Version.BUILD_COMMIT.substring(0, 7));
        }
        log.info(hello);

        if (!this.directory.exists())
            this.directory.mkdirs();

        this.validateConfig();

        if (this.executorService == null)
            this.executorService = new ScheduledThreadPoolExecutor(this.config.getThreadCount());

        if (this.transactionManager == null) {
            this.transactionManager = new ThreadContextTransactionManager(
                    new DocumentFileWrapper(new File(directory, "xflat_transaction")));
        }

        this.InitializeScheduledTasks();

        Runtime.getRuntime().addShutdownHook(this.shutdownHook);

        //recover transactional state if necessary

        this.transactionManager.recover(this);

        //done initializing
        this.state.set(DatabaseState.Running);
    } catch (Exception ex) {
        this.state.set(DatabaseState.Uninitialized);
        throw new XFlatException("Initialization error", ex);
    }
}

From source file:x10.x10rt.yarn.ApplicationMaster.java

public ApplicationMaster(String[] args) throws Exception {
    this.conf = new YarnConfiguration();
    Map<String, String> envs = System.getenv();

    ContainerId containerId = ConverterUtils.toContainerId(envs.get(Environment.CONTAINER_ID.name()));
    appAttemptID = containerId.getApplicationAttemptId();

    LOG.info("Application master for app" + ", appId=" + appAttemptID.getApplicationId().getId()
            + ", clustertimestamp=" + appAttemptID.getApplicationId().getClusterTimestamp() + ", attemptId="
            + appAttemptID.getAttemptId());

    initialNumPlaces = Integer.parseInt(envs.get(X10_NPLACES));
    coresPerPlace = Integer.parseInt(envs.get(X10_NTHREADS));
    nthreads = coresPerPlace;//from   w w w.jav a  2 s  . c  o m
    links = new HashMap<Integer, ApplicationMaster.CommunicationLink>(initialNumPlaces);
    places = new HashMap<ContainerId, Integer>(initialNumPlaces);
    pendingReads = new HashMap<SocketChannel, ByteBuffer>();
    selector = Selector.open();
    this.args = args;
    this.appName = System.getProperty(X10_YARN_MAIN);

    // look for max memory argument
    this.memoryPerPlaceInMb = 4024; // default of 1Gb per place
    for (int i = 0; i < args.length; i++) {
        try {
            if (args[i].startsWith("-Xmx")) {
                if (args[i].toLowerCase().endsWith("g"))
                    this.memoryPerPlaceInMb = Integer.parseInt(args[i].substring(4, args[i].length() - 1))
                            * 1024;
                else if (args[i].toLowerCase().endsWith("m"))
                    this.memoryPerPlaceInMb = Integer.parseInt(args[i].substring(4, args[i].length() - 1));
                else if (args[i].toLowerCase().endsWith("k"))
                    this.memoryPerPlaceInMb = Integer.parseInt(args[i].substring(4, args[i].length() - 1))
                            / 1024;
                else
                    this.memoryPerPlaceInMb = Integer.parseInt(args[i].substring(4)) / 1024 / 1024;
                break;
            }
        } catch (NumberFormatException e) {
            // ignore, use default value
            e.printStackTrace();
        }
    }

    if (envs.containsKey(X10YARNENV_ + X10_YARN_KILL)) {
        placeKiller = new ScheduledThreadPoolExecutor(1);
        // things to kill takes the form place:delayInSeconds,place:delayInSeconds,etc.  e.g. "2:2,3:3" will kill place 2 after 2 seconds, 3 after 3 seconds
        String thingsToKill = System.getenv(X10YARNENV_ + X10_YARN_KILL);
        // TODO: format error checking
        String[] sets = thingsToKill.split(",");
        pendingKills = new HashMap<Integer, Integer>(sets.length);
        for (String set : sets) {
            String[] place_delay = set.split(":");
            int place = Integer.parseInt(place_delay[0]);
            int delay = Integer.parseInt(place_delay[1]);
            pendingKills.put(place, delay);
        }
    } else {
        placeKiller = null;
        pendingKills = null;
    }
}

From source file:com.linkedin.pinot.transport.netty.NettySingleConnectionIntegrationTest.java

/**
 * This test attempts to use the connection mechanism the same way as ScatterGatherImpl.SingleRequestHandler does.
 */// w ww .  j av  a  2 s. com
@SuppressWarnings("unchecked")
@Test
public void testServerShutdownLeak() throws Exception {
    PooledNettyClientResourceManager resourceManager = new PooledNettyClientResourceManager(
            new NioEventLoopGroup(), new HashedWheelTimer(), new NettyClientMetrics(null, "abc"));
    ExecutorService executorService = Executors.newCachedThreadPool();
    ScheduledExecutorService timeoutExecutor = new ScheduledThreadPoolExecutor(5);

    KeyedPool<PooledNettyClientResourceManager.PooledClientConnection> keyedPool = new KeyedPoolImpl<>(
            /*minSize=*/2, /*maxSize=*/3, /*idleTimeoutMs=*/100000L, /*maxPending=*/1, resourceManager,
            timeoutExecutor, executorService, new MetricsRegistry());
    resourceManager.setPool(keyedPool);

    try {
        keyedPool.start();

        // The act of calling checkoutObject() creates a new AsyncPool and places a request for a new connection
        // NOTE: since no connections are available in the beginning, and the min connections are still being filled, we
        // always end up creating one more connection than the min connections
        Assert.assertNotNull(keyedPool.checkoutObject(_clientServer).getOne());

        // Use reflection to get the pool and the waiters queue
        Field keyedPoolField = KeyedPoolImpl.class.getDeclaredField("_keyedPool");
        keyedPoolField.setAccessible(true);
        Map<ServerInstance, AsyncPool<NettyClientConnection>> poolMap = (Map<ServerInstance, AsyncPool<NettyClientConnection>>) keyedPoolField
                .get(keyedPool);
        AsyncPool<NettyClientConnection> pool = poolMap.get(_clientServer);
        Field waitersField = AsyncPoolImpl.class.getDeclaredField("_waiters");
        waitersField.setAccessible(true);
        LinkedDequeue waitersQueue = (LinkedDequeue) waitersField.get(pool);

        // Make sure the min pool size is filled out
        Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);

        PoolStats stats = pool.getStats();
        Assert.assertEquals(stats.getPoolSize(), 3);
        Assert.assertEquals(stats.getIdleCount(), 2);
        Assert.assertEquals(stats.getCheckedOut(), 1);
        Assert.assertEquals(waitersQueue.size(), 0);

        // Get two more connections to the server and leak them
        Assert.assertNotNull(keyedPool.checkoutObject(_clientServer).getOne());
        Assert.assertNotNull(keyedPool.checkoutObject(_clientServer).getOne());
        stats = pool.getStats();
        Assert.assertEquals(stats.getPoolSize(), 3);
        Assert.assertEquals(stats.getIdleCount(), 0);
        Assert.assertEquals(stats.getCheckedOut(), 3);
        Assert.assertEquals(waitersQueue.size(), 0);

        // Try to get one more connection
        // We should get an exception because we don't have a free connection to the server
        ServerResponseFuture<PooledNettyClientResourceManager.PooledClientConnection> serverResponseFuture = keyedPool
                .checkoutObject(_clientServer);
        try {
            serverResponseFuture.getOne(1, TimeUnit.SECONDS);
            Assert.fail("Get connection even no connections available");
        } catch (TimeoutException e) {
            // PASS
        }
        stats = pool.getStats();
        Assert.assertEquals(stats.getPoolSize(), 3);
        Assert.assertEquals(stats.getIdleCount(), 0);
        Assert.assertEquals(stats.getCheckedOut(), 3);
        Assert.assertEquals(waitersQueue.size(), 1);
        serverResponseFuture.cancel(true);
        Assert.assertEquals(waitersQueue.size(), 0);

        // If the server goes down, we should release all 3 connections and be able to get new connections
        closeServerConnection();
        setUp();
        stats = pool.getStats();
        Assert.assertEquals(stats.getPoolSize(), 2);
        Assert.assertEquals(stats.getIdleCount(), 2);

        // Try to get 3 new connections
        for (int i = 0; i < 3; i++) {
            Assert.assertNotNull(keyedPool.checkoutObject(_clientServer).getOne());
        }
    } finally {
        keyedPool.shutdown();
        executorService.shutdown();
        timeoutExecutor.shutdown();
    }
}

From source file:com.lucidtechnics.blackboard.Blackboard.java

private void init() {
    java.io.File file = new java.io.File(getAppsHome());

    if (file.exists() == false) {
        file.mkdirs();//from   w w w  . j ava2s. c o  m
    }

    java.io.File appsDirectory = new java.io.File(getAppsHome());

    if (appsDirectory.isDirectory() != true) {
        throw new RuntimeException(
                "Directory: " + getAppsHome() + " as set in blackboard.apps.home is not a directory");
    }

    java.io.File[] directoryFiles = appsDirectory.listFiles();

    for (int i = 0; i < directoryFiles.length; i++) {
        if (directoryFiles[i].isDirectory() == true) {
            String appName = directoryFiles[i].getName();

            if (logger.isInfoEnabled() == true) {
                logger.info("Configuring app: " + appName);
            }

            java.io.File[] workspaceDirectoryFiles = directoryFiles[i].listFiles();

            for (int j = 0; j < workspaceDirectoryFiles.length; j++) {
                if (workspaceDirectoryFiles[j].isDirectory() == true) {
                    String workspaceName = workspaceDirectoryFiles[j].getName();

                    if (logger.isInfoEnabled() == true) {
                        logger.info("Processing workspace: " + workspaceName);
                    }

                    java.io.File[] eventDirectoryFiles = workspaceDirectoryFiles[j].listFiles();

                    WorkspaceConfiguration workspaceConfiguration = configureWorkspace(appName, workspaceName,
                            workspaceDirectoryFiles[j]);

                    for (int k = 0; k < eventDirectoryFiles.length; k++) {
                        if (eventDirectoryFiles[k].isDirectory() == true) {
                            processEventPlans(appName, workspaceName, workspaceConfiguration,
                                    eventDirectoryFiles[k]);
                        }
                    }
                }
            }
        }
    }

    if (logger.isInfoEnabled() == true) {
        logger.info("Loaded event configurations: " + getEventToWorkspaceMap());
    }

    setBlackboardExecutor(new ThreadPoolExecutor(1, 1, 100, TimeUnit.SECONDS, new LinkedBlockingQueue()));

    setScheduledBlackboardExecutor(new ScheduledThreadPoolExecutor(getMaxScheduledBlackboardThread()));

    for (int i = 0; i <= getMaxWorkspaceThread(); i++) {
        getWorkspaceExecutorMap().put(i,
                new ThreadPoolExecutor(1, 1, 100, TimeUnit.SECONDS, new LinkedBlockingQueue()));
    }

    setPersistenceExecutor(new ThreadPoolExecutor(getMaxPersistenceThread(), getMaxPersistenceThread(), 100,
            TimeUnit.SECONDS, new LinkedBlockingQueue()));

    if (logger.isInfoEnabled() == true) {
        logger.info("Blackboard Workspace Server Initialization Inception.");
        logger.info("Apache 2.0 Open Source License.");
        logger.info("Copyright Owner - Lucid Technics, LLC.");
        logger.info("Authors - Bediako Ntodi George and David Yuctan Hodge.");
        logger.info("Initialization was successful.");
    }

    org.apache.jcs.JCS.setConfigFilename("/blackboard.ccf");
}

From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProvider.java

public void start() {
    if (!running) {
        long initialDelay = DateHelper.getMillisecondsUntilMidnight(System.currentTimeMillis(), timeZone);

        executor.start();//from www .j a  v  a2 s  . c o m

        restartFileWatcher();
        reloadScheduleFile();

        logger.debug("New day will start in {} seconds", (initialDelay / 1000));
        resetDayExecutor = new ScheduledThreadPoolExecutor(1);
        resetDayExecutor.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                resetForNewDay(System.currentTimeMillis());
            }
        }, initialDelay, MS_24_HOURS, TimeUnit.MILLISECONDS);

        running = true;
    }
}

From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    //Force the use of slf4j logger in all JBoss log uses in this wars context!!!
    jboss = ContainerUtils.isJBoss();// ww w  .  java 2  s  .c  o  m
    if (jboss) {
        oldJBoss = ContainerUtils.isOldJBoss();
    }
    if (oldJBoss) {
        System.setProperty("org.jboss.logging.provider", "slf4j");
    }

    failOver = servletContextEvent.getServletContext().getRealPath("/");
    MaintenanceFilter.siteDown.start();
    context = servletContextEvent.getServletContext();

    configManager = new ConfigManager(context);

    Properties cadmiumProperties = configManager.getPropertiesByContext(context, "/WEB-INF/cadmium.properties");

    Properties configProperties = new Properties();
    configProperties = configManager.getSystemProperties();
    configProperties.putAll(cadmiumProperties);

    sharedContentRoot = sharedContextRoot(configProperties, context, log);

    // compute the directory for this application, based on the war name.
    warName = WarUtils.getWarName(context);

    vHostName = getVHostName(context);

    applicationContentRoot = applicationContentRoot(sharedContentRoot, warName, log);

    executor = new ScheduledThreadPoolExecutor(1);
    executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setKeepAliveTime(5, TimeUnit.MINUTES);
    executor.setMaximumPoolSize(Math.min(Runtime.getRuntime().availableProcessors(), 4));

    configProperties = configManager.appendProperties(configProperties,
            new File(applicationContentRoot, CONFIG_PROPERTIES_FILE));

    configManager.setDefaultProperties(configProperties);
    configManager.setDefaultPropertiesFile(new File(applicationContentRoot, CONFIG_PROPERTIES_FILE));

    try {
        LogUtils.configureLogback(servletContextEvent.getServletContext(), applicationContentRoot,
                getVHostName(servletContextEvent.getServletContext()), log);
    } catch (IOException e) {
        log.error("Failed to reconfigure logging", e);
    }

    if ((sshDir = getSshDir(configProperties, sharedContentRoot, log)) != null) {
        GitService.setupSsh(sshDir.getAbsolutePath());
    }

    String repoDir = servletContextEvent.getServletContext().getInitParameter("repoDir");
    if (repoDir != null && repoDir.trim().length() > 0) {
        this.repoDir = repoDir;
    }
    String contentDir = servletContextEvent.getServletContext().getInitParameter("contentDir");
    if (contentDir != null && contentDir.trim().length() > 0) {
        this.contentDir = contentDir;
    }
    if (configProperties.containsKey(LAST_UPDATED_DIR)) {
        File cntDir = new File(configProperties.getProperty(LAST_UPDATED_DIR));
        if (cntDir.exists() && cntDir.canRead()) {
            this.contentDir = cntDir.getName();
        }
    }
    File repoFile = new File(this.applicationContentRoot, this.repoDir);
    if (repoFile.isDirectory() && repoFile.canWrite()) {
        this.repoDir = repoFile.getAbsoluteFile().getAbsolutePath();
    } else {
        log.warn("The repo directory may not have been initialized yet.");
        this.repoDir = repoFile.getAbsoluteFile().getAbsolutePath();
    }

    File contentFile = new File(this.applicationContentRoot, this.contentDir);
    if (contentFile.exists() && contentFile.isDirectory() && contentFile.canWrite()) {
        this.contentDir = contentFile.getAbsoluteFile().getAbsolutePath();
    } else {
        log.warn("The content directory may not have been initialized yet.");
        this.contentDir = contentFile.getAbsoluteFile().getAbsolutePath();
    }

    String channelCfgUrl = configProperties.getProperty(JGROUPS_CHANNEL_CONFIG_URL);
    //String channelCfgUrl = System.getProperty(JGROUPS_CHANNEL_CONFIG_URL);
    if (channelCfgUrl != null) {
        File channelCfgFile = null;
        URL fileUrl = null;
        try {
            fileUrl = new URL(channelCfgUrl);
        } catch (Exception e) {
            channelCfgFile = new File(channelCfgUrl);
        }
        if (fileUrl == null && channelCfgFile != null) {
            if (!channelCfgFile.isAbsolute() && !channelCfgFile.exists()) {
                channelCfgFile = new File(this.sharedContentRoot, channelCfgUrl);
                if (channelCfgFile.exists()) {
                    this.channelConfigUrl = "file://" + channelCfgFile.getAbsoluteFile().getAbsolutePath();
                }
            } else {
                this.channelConfigUrl = "file://" + channelCfgFile.getAbsoluteFile().getAbsolutePath();
            }
        } else if (fileUrl != null) {
            this.channelConfigUrl = fileUrl.toString();
        }
    }
    Vfs.addDefaultURLTypes(new JBossVfsUrlType());
    reflections = Reflections.collect();
    Module modules[] = new Module[] { createServletModule(), createModule() };
    InternalInjectorCreator guiceCreator = new InternalInjectorCreator().stage(Stage.DEVELOPMENT)
            .addModules(Arrays.asList(modules));
    try {
        injector = guiceCreator.build();

        //injector = Guice.createInjector(createServletModule(), createModule());

        // run the postConstruct methods.
        jsr250Executor = Jsr250Utils.createJsr250Executor(injector, log, Scopes.SINGLETON);
        jsr250Executor.postConstruct();

        super.contextInitialized(servletContextEvent);
        File graphFile = new File(applicationContentRoot, "injector.dot");
        graphGood(graphFile, injector);
    } catch (Throwable t) {
        try {
            log.error("Failed to initialize...", t);
            Method primaryInjector = InternalInjectorCreator.class.getDeclaredMethod("primaryInjector");
            primaryInjector.setAccessible(true);
            injector = (Injector) primaryInjector.invoke(guiceCreator);
            if (injector == null) {
                log.error("Injector must not have been created.");
            } else {
                log.error("Found injector {}", injector);
            }
        } catch (Throwable e) {
            log.error("Failed to retrieve injector that failed to initialize.", e);
        }
        throw new RuntimeException("Failed to Initialize", t);
    }
}

From source file:org.hawkular.alerter.elasticsearch.ElasticsearchAlerter.java

private synchronized void update() {
    final Set<TriggerKey> existingKeys = queryFutures.keySet();
    final Set<TriggerKey> activeKeys = activeTriggers.keySet();

    Set<TriggerKey> newKeys = new HashSet<>();
    Set<TriggerKey> canceledKeys = new HashSet<>();

    Set<TriggerKey> updatedKeys = new HashSet<>(activeKeys);
    updatedKeys.retainAll(activeKeys);// w w w. ja v  a 2 s .co  m

    activeKeys.stream().filter(key -> !existingKeys.contains(key)).forEach(key -> newKeys.add(key));
    existingKeys.stream().filter(key -> !activeKeys.contains(key)).forEach(key -> canceledKeys.add(key));

    log.debugf("newKeys %s", newKeys);
    log.debugf("updatedKeys %s", updatedKeys);
    log.debugf("canceledKeys %s", canceledKeys);

    canceledKeys.stream().forEach(key -> {
        ScheduledFuture canceled = queryFutures.remove(key);
        if (canceled != null) {
            canceled.cancel(false);
        }
    });
    updatedKeys.stream().forEach(key -> {
        ScheduledFuture updated = queryFutures.remove(key);
        if (updated != null) {
            updated.cancel(false);
        }
    });

    if (scheduledExecutor == null) {
        scheduledExecutor = new ScheduledThreadPoolExecutor(THREAD_POOL_SIZE);
    }

    newKeys.addAll(updatedKeys);

    for (TriggerKey key : newKeys) {
        Trigger t = activeTriggers.get(key);
        String interval = t.getContext().get(INTERVAL) == null ? INTERVAL_DEFAULT
                : t.getContext().get(INTERVAL);
        queryFutures.put(key,
                scheduledExecutor.scheduleAtFixedRate(new ElasticsearchQuery(t, defaultProperties, alerts), 0L,
                        getIntervalValue(interval), getIntervalUnit(interval)));

    }
}

From source file:org.apache.falcon.service.EntitySLAMonitoringService.java

@Override
public void init() throws FalconException {

    String freq = StartupProperties.get().getProperty("entity.sla.statusCheck.frequency.seconds", "600");
    statusCheckFrequencySeconds = Integer.parseInt(freq);

    freq = StartupProperties.get().getProperty("entity.sla.lookAheadWindow.millis", "900000");
    lookAheadWindowMillis = Integer.parseInt(freq);
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    addPendingEntityInstances(now());/*  www.j av  a 2  s .  c  om*/
    executor.scheduleWithFixedDelay(new Monitor(), 0, statusCheckFrequencySeconds, TimeUnit.SECONDS);
}

From source file:ddf.metrics.reporting.internal.rrd4j.JmxCollector.java

/**
 * Configures a scheduled threaded executor to poll the metric's MBean periodically
 * and add a sample to the RRD file with the metric's current value.
 * //from w w  w.  j av a2 s.  co  m
 * @throws CollectorException
 */
public void updateSamples() throws CollectorException {
    LOGGER.trace("ENTERING: updateSamples");

    if (executor == null) {
        executor = new ScheduledThreadPoolExecutor(1);
    }

    final Runnable updater = new Runnable() {
        public void run() {
            Object attr = null;
            try {
                attr = localMBeanServer.getAttribute(new ObjectName(mbeanName), mbeanAttributeName);

                LOGGER.trace("Sampling attribute " + mbeanAttributeName + " from MBean " + mbeanName);

                // Cast the metric's sampled value to the appropriate data type
                double val = 0;
                if (attr instanceof Integer) {
                    val = (Integer) attr;
                } else if (attr instanceof Long) {
                    val = ((Long) attr).intValue();
                } else if (attr instanceof Float) {
                    val = ((Float) attr);
                } else if (attr instanceof Double) {
                    val = ((Double) attr);
                } else {
                    throw new IllegalArgumentException(
                            "Unsupported type " + attr + " for attribute " + mbeanAttributeName);
                }

                LOGGER.trace("MBean attribute " + mbeanAttributeName + " has value = " + val);

                // If first time this metric has been sampled, then need to create a
                // sample in the RRD file
                if (sample == null) {
                    sample = rrdDb.createSample();
                }

                try {
                    // Add metric's sample to RRD file with current timestamp (i.e., "NOW")
                    sample.setAndUpdate("NOW:" + val);
                } catch (IllegalArgumentException iae) {
                    LOGGER.error("Dropping sample of datasource " + rrdDataSourceName, iae);
                }
            } catch (Exception e) {
                LOGGER.warn("Problems getting MBean attribute " + mbeanAttributeName, e);
            }
        }
    };

    // Setup threaded scheduler to retrieve this MBean attribute's value
    // at the specified sample rate
    LOGGER.debug("Setup ScheduledThreadPoolExecutor for MBean " + mbeanName);
    executor.scheduleWithFixedDelay(updater, 0, sampleRate, TimeUnit.SECONDS);

    LOGGER.trace("EXITING: updateSamples");
}

From source file:org.gdg.frisbee.android.cache.ModelCache.java

synchronized void setDiskCache(DiskLruCache diskCache) {
    mDiskCache = diskCache;//from w w  w .j  av  a  2 s.c  om

    if (null != diskCache) {
        mDiskCacheEditLocks = new HashMap<String, ReentrantLock>();
        mDiskCacheFlusherExecutor = new ScheduledThreadPoolExecutor(1);
        mDiskCacheFlusherRunnable = new DiskCacheFlushRunnable(diskCache);
    }
}