List of usage examples for com.google.common.base FinalizableReferenceQueue FinalizableReferenceQueue
public FinalizableReferenceQueue()
From source file:org.javabits.yar.guice.SimpleRegistry.java
SimpleRegistry(WatchableRegistrationContainer registrationContainer, long timeout, TimeUnit unit) { referenceQueue = new FinalizableReferenceQueue(); this.registrationContainer = registrationContainer; //TODO test performance of the linked vs. array or any other blocking. may provide a new builder feature to setup the size of the queue registryActionQueue = new LinkedBlockingQueue<>(); Thread registryActionThread = new Thread(new RegistryActionHandler(registryActionQueue), "yar-action-handler"); registryActionThread.setDaemon(true); registryActionThread.start();//ww w. j av a 2 s .c om this.defaultTimeOut = timeout; this.defaultTimeoutUnit = unit; }
From source file:org.apache.flex.compiler.internal.workspaces.Workspace.java
/** * Constructor/*from www.java 2s. c om*/ * * @param es {@link ExecutorService} to use to do background work in this * workspace. */ public Workspace(ExecutorService es) { executorService = es; profilingDelegate = null; invalidationListeners = new LinkedHashSet<IInvalidationListener>(); swcManager = new SWCManager(this); mxmlDataManager = new MXMLDataManager(); projects = new MapMaker().weakKeys().makeMap(); pathToFileSpecMap = new HashMap<String, IFileSpecification>(); pathToCompilationUnitMapping = new StringToCompilationUnitMap(); includeFilesToIncludingCompilationUnitMapping = new StringToCompilationUnitMap(); packageNamespaceDefinitionCache = new PackageNamespaceDefinitionCache(); embedDataCache = new WeakHashMap<EmbedData, EmbedData>(); embedLock = new ReentrantReadWriteLock(); invisibleCompilationUnitReferenceQueue = new FinalizableReferenceQueue(); asDocDelegate = NilASDocDelegate.get(); buildSync = new BuildSynchronizationState(); }
From source file:org.itas.core.dbpool.BoneCP.java
/** * Constructor.//from w w w . j a v a 2 s . c o m * @param config Configuration for pool * @throws SQLException on error */ public BoneCP(BoneCPConfig config) throws SQLException { this.config = config; config.sanitize(); this.poolAvailabilityThreshold = config.getPoolAvailabilityThreshold(); this.connectionTimeout = config.getConnectionTimeout(); AcquireFailConfig acquireConfig = new AcquireFailConfig(); acquireConfig.setAcquireRetryAttempts(new AtomicInteger(0)); acquireConfig.setAcquireRetryDelay(0); acquireConfig.setLogMessage("Failed to obtain initial connection"); if (!config.isLazyInit()) { try { Connection sanityConnection = obtainRawInternalConnection(); sanityConnection.close(); } catch (Exception e) { if (config.getConnectionHook() != null) { config.getConnectionHook().onAcquireFail(e, acquireConfig); } throw new SQLException(String.format(ERROR_TEST_CONNECTION, config.getJdbcUrl(), config.getUsername(), PoolUtil.stringifyException(e))); } } if (!config.isDisableConnectionTracking()) { this.finalizableRefQueue = new FinalizableReferenceQueue(); } this.asyncExecutor = Executors.newCachedThreadPool(); int helperThreads = config.getReleaseHelperThreads(); this.releaseHelperThreadsConfigured = helperThreads > 0; this.config = config; this.partitions = new ConnectionPartition[config.getPartitionCount()]; String suffix = ""; if (config.getPoolName() != null) { suffix = "-" + config.getPoolName(); } if (this.releaseHelperThreadsConfigured) { this.releaseHelper = Executors.newFixedThreadPool(helperThreads * config.getPartitionCount(), new CustomThreadFactory("BoneCP-release-thread-helper-thread" + suffix, true)); } this.keepAliveScheduler = Executors.newScheduledThreadPool(config.getPartitionCount(), new CustomThreadFactory("BoneCP-keep-alive-scheduler" + suffix, true)); this.connectionsScheduler = Executors.newFixedThreadPool(config.getPartitionCount(), new CustomThreadFactory("BoneCP-pool-watch-thread" + suffix, true)); this.partitionCount = config.getPartitionCount(); this.closeConnectionWatch = config.isCloseConnectionWatch(); if (this.closeConnectionWatch) { logger.warn( "Thread close connection monitoring has been enabled. This will negatively impact on your performance. Only enable this option for debugging purposes!"); this.closeConnectionExecutor = Executors .newCachedThreadPool(new CustomThreadFactory("BoneCP-connection-watch-thread" + suffix, true)); } for (int p = 0; p < config.getPartitionCount(); p++) { ConnectionPartition connectionPartition = new ConnectionPartition(this); this.partitions[p] = connectionPartition; this.partitions[p].setFreeConnections( new ArrayBlockingQueue<ConnectionHandle>(config.getMaxConnectionsPerPartition())); if (!config.isLazyInit()) { for (int i = 0; i < config.getMinConnectionsPerPartition(); i++) { final ConnectionHandle handle = new ConnectionHandle(config.getJdbcUrl(), config.getUsername(), config.getPassword(), this); this.partitions[p].addFreeConnection(handle); } } if (config.getIdleConnectionTestPeriod() > 0) { final Runnable connectionTester = new ConnectionTesterThread(connectionPartition, this.keepAliveScheduler, this, config.getIdleMaxAge(), config.getIdleConnectionTestPeriod()); this.keepAliveScheduler.submit(connectionTester); } // watch this partition for low no of threads this.connectionsScheduler.execute(new PoolWatchThread(connectionPartition, this)); } if (!this.config.isDisableJMX()) { initJMX(); } }
From source file:com.jolbox.bonecp.BoneCP.java
/** * Constructor./*from w w w . j ava 2 s .c o m*/ * @param config Configuration for pool * @throws SQLException on error */ public BoneCP(BoneCPConfig config) throws SQLException { this.config = config; config.sanitize(); this.statisticsEnabled = config.isStatisticsEnabled(); this.closeConnectionWatchTimeoutInMs = config.getCloseConnectionWatchTimeoutInMs(); this.poolAvailabilityThreshold = config.getPoolAvailabilityThreshold(); this.connectionTimeoutInMs = config.getConnectionTimeoutInMs(); if (this.connectionTimeoutInMs == 0) { this.connectionTimeoutInMs = Long.MAX_VALUE; } this.defaultReadOnly = config.getDefaultReadOnly(); this.defaultCatalog = config.getDefaultCatalog(); this.defaultTransactionIsolationValue = config.getDefaultTransactionIsolationValue(); this.defaultAutoCommit = config.getDefaultAutoCommit(); AcquireFailConfig acquireConfig = new AcquireFailConfig(); acquireConfig.setAcquireRetryAttempts(new AtomicInteger(0)); acquireConfig.setAcquireRetryDelayInMs(0); acquireConfig.setLogMessage("Failed to obtain initial connection"); if (!config.isLazyInit()) { try { Connection sanityConnection = obtainRawInternalConnection(); sanityConnection.close(); } catch (Exception e) { if (config.getConnectionHook() != null) { config.getConnectionHook().onAcquireFail(e, acquireConfig); } // #ifdef JDK6 throw new SQLException(String.format(ERROR_TEST_CONNECTION, config.getJdbcUrl(), config.getUsername(), PoolUtil.stringifyException(e)), e); // #endif /* #ifdef JDK5 throw new SQLException(String.format(ERROR_TEST_CONNECTION, config.getJdbcUrl(), config.getUsername(), PoolUtil.stringifyException(e))); #endif JDK5 */ } } if (!config.isDisableConnectionTracking()) { this.finalizableRefQueue = new FinalizableReferenceQueue(); } this.asyncExecutor = Executors.newCachedThreadPool(); int helperThreads = config.getReleaseHelperThreads(); this.releaseHelperThreadsConfigured = helperThreads > 0; this.statementReleaseHelperThreadsConfigured = config.getStatementReleaseHelperThreads() > 0; this.config = config; this.partitions = new ConnectionPartition[config.getPartitionCount()]; String suffix = ""; if (config.getPoolName() != null) { suffix = "-" + config.getPoolName(); } if (this.releaseHelperThreadsConfigured) { this.releaseHelper = Executors.newFixedThreadPool(helperThreads * config.getPartitionCount(), new CustomThreadFactory("BoneCP-release-thread-helper-thread" + suffix, true)); } this.keepAliveScheduler = Executors.newScheduledThreadPool(config.getPartitionCount(), new CustomThreadFactory("BoneCP-keep-alive-scheduler" + suffix, true)); this.maxAliveScheduler = Executors.newScheduledThreadPool(config.getPartitionCount(), new CustomThreadFactory("BoneCP-max-alive-scheduler" + suffix, true)); this.connectionsScheduler = Executors.newFixedThreadPool(config.getPartitionCount(), new CustomThreadFactory("BoneCP-pool-watch-thread" + suffix, true)); this.partitionCount = config.getPartitionCount(); this.closeConnectionWatch = config.isCloseConnectionWatch(); boolean queueLIFO = config.getServiceOrder() != null && config.getServiceOrder().equalsIgnoreCase("LIFO"); if (this.closeConnectionWatch) { logger.warn(THREAD_CLOSE_CONNECTION_WARNING); this.closeConnectionExecutor = Executors .newCachedThreadPool(new CustomThreadFactory("BoneCP-connection-watch-thread" + suffix, true)); } for (int p = 0; p < config.getPartitionCount(); p++) { ConnectionPartition connectionPartition = new ConnectionPartition(this); this.partitions[p] = connectionPartition; TransferQueue<ConnectionHandle> connectionHandles; if (config.getMaxConnectionsPerPartition() == config.getMinConnectionsPerPartition()) { // if we have a pool that we don't want resized, make it even faster by ignoring // the size constraints. connectionHandles = queueLIFO ? new LIFOQueue<ConnectionHandle>() : new LinkedTransferQueue<ConnectionHandle>(); } else { connectionHandles = queueLIFO ? new LIFOQueue<ConnectionHandle>(this.config.getMaxConnectionsPerPartition()) : new BoundedLinkedTransferQueue<ConnectionHandle>( this.config.getMaxConnectionsPerPartition()); } this.partitions[p].setFreeConnections(connectionHandles); if (!config.isLazyInit()) { for (int i = 0; i < config.getMinConnectionsPerPartition(); i++) { final ConnectionHandle handle = new ConnectionHandle(config.getJdbcUrl(), config.getUsername(), config.getPassword(), this); this.partitions[p].addFreeConnection(handle); } } if (config.getIdleConnectionTestPeriodInMinutes() > 0 || config.getIdleMaxAgeInMinutes() > 0) { final Runnable connectionTester = new ConnectionTesterThread(connectionPartition, this.keepAliveScheduler, this, config.getIdleMaxAge(TimeUnit.MILLISECONDS), config.getIdleConnectionTestPeriod(TimeUnit.MILLISECONDS), queueLIFO); long delayInMinutes = config.getIdleConnectionTestPeriodInMinutes(); if (delayInMinutes == 0L) { delayInMinutes = config.getIdleMaxAgeInMinutes(); } if (config.getIdleMaxAgeInMinutes() != 0 && config.getIdleConnectionTestPeriodInMinutes() != 0 && config.getIdleMaxAgeInMinutes() < delayInMinutes) { delayInMinutes = config.getIdleMaxAgeInMinutes(); } this.keepAliveScheduler.schedule(connectionTester, delayInMinutes, TimeUnit.MINUTES); } if (config.getMaxConnectionAgeInSeconds() > 0) { final Runnable connectionMaxAgeTester = new ConnectionMaxAgeThread(connectionPartition, this.maxAliveScheduler, this, config.getMaxConnectionAge(TimeUnit.MILLISECONDS), queueLIFO); this.maxAliveScheduler.schedule(connectionMaxAgeTester, config.getMaxConnectionAgeInSeconds(), TimeUnit.SECONDS); } // watch this partition for low no of threads this.connectionsScheduler.execute(new PoolWatchThread(connectionPartition, this)); } initStmtReleaseHelper(suffix); if (!this.config.isDisableJMX()) { initJMX(); } }