Search in sources :

Example 1 with ThreadPooledLockService

use of com.palantir.lock.impl.ThreadPooledLockService in project atlasdb by palantir.

the class LockCreator method createThreadPoolingLockService.

public CloseableLockService createThreadPoolingLockService() {
    // TODO (jkong): Live reload slow lock timeout, plus clients (issue #2342)
    // TODO (?????): Rewrite ThreadPooled to cope with live reload, and/or remove ThreadPooled (if using Async)
    TimeLockRuntimeConfiguration timeLockRuntimeConfiguration = runtime.get();
    CloseableLockService lockServiceNotUsingThreadPooling = createTimeLimitedLockService(timeLockRuntimeConfiguration.slowLockLogTriggerMillis());
    if (!deprecated.useClientRequestLimit()) {
        return lockServiceNotUsingThreadPooling;
    }
    int availableThreads = deprecated.availableThreads();
    // TODO(nziebart): Since the number of clients can grow dynamically, we can't compute a correct and useful
    // value for the local threadpool size at this point. Given that async lock service exists, and doesn't need
    // a thread pool, it's likely we won't fix this and will eventually remove the thread pooled lock service.
    // However, for the time being, it's still useful to have global limiting for services that need to use the
    // legacy lock service.
    int localThreadPoolSize = -1;
    int sharedThreadPoolSize = availableThreads;
    synchronized (this) {
        if (sharedThreadPool.availablePermits() == -1) {
            sharedThreadPool.release(sharedThreadPoolSize + 1);
        }
    }
    return new ThreadPooledLockService(lockServiceNotUsingThreadPooling, localThreadPoolSize, sharedThreadPool);
}
Also used : CloseableLockService(com.palantir.lock.CloseableLockService) ThreadPooledLockService(com.palantir.lock.impl.ThreadPooledLockService) TimeLockRuntimeConfiguration(com.palantir.timelock.config.TimeLockRuntimeConfiguration)

Example 2 with ThreadPooledLockService

use of com.palantir.lock.impl.ThreadPooledLockService in project atlasdb by palantir.

the class ThreadPooledLockServiceTest method closesDelegate.

@Test
public void closesDelegate() throws IOException {
    CloseableLockService delegate = mock(CloseableLockService.class);
    ThreadPooledLockService pooledService = new ThreadPooledLockService(delegate, 1, new Semaphore(1));
    pooledService.close();
    verify(delegate).close();
}
Also used : CloseableLockService(com.palantir.lock.CloseableLockService) Semaphore(java.util.concurrent.Semaphore) ThreadPooledLockService(com.palantir.lock.impl.ThreadPooledLockService) Test(org.junit.Test)

Aggregations

CloseableLockService (com.palantir.lock.CloseableLockService)2 ThreadPooledLockService (com.palantir.lock.impl.ThreadPooledLockService)2 TimeLockRuntimeConfiguration (com.palantir.timelock.config.TimeLockRuntimeConfiguration)1 Semaphore (java.util.concurrent.Semaphore)1 Test (org.junit.Test)1