Search in sources :

Example 1 with NexusThreadFactory

use of org.sonatype.nexus.thread.NexusThreadFactory in project nexus-public by sonatype.

the class EventExecutor method doStart.

/**
 * Move from direct to asynchronous subscriber processing.
 */
@Override
protected void doStart() throws Exception {
    ThreadPoolExecutor threadPool = new ThreadPoolExecutor(0, HOST_THREAD_POOL_SIZE, 60L, TimeUnit.SECONDS, // rendezvous only, zero capacity
    new SynchronousQueue<>(fairThreading), new NexusThreadFactory("event", "event-manager"), CALLER_RUNS_FAILSAFE);
    eventProcessor = NexusExecutorService.forCurrentSubject(threadPool);
    if (affinityEnabled) {
        Supplier<Executor> coordinator;
        if (singleCoordinator) {
            // like singleThreadExecutor but with custom rejection handler
            ThreadPoolExecutor affinityThread = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, // allow queueing up of requests
            new LinkedBlockingQueue<>(), new NexusThreadFactory("affinity", "affinity-manager"), CALLER_RUNS_FAILSAFE);
            affinityProcessor = NexusExecutorService.forCurrentSubject(affinityThread);
            // use single-thread queue to coordinate all events (delivery to subscribers is still multi-threaded)
            coordinator = () -> affinityProcessor;
        } else {
            // multi-threaded coordination and delivery, with sequential coordination for events with same affinity
            // wraps behaviour on top of eventProcessor
            coordinator = () -> newSequentialExecutor(eventProcessor);
        }
        affinityBarriers = CacheBuilder.newBuilder().maximumSize(affinityCacheSize).build(CacheLoader.from(() -> new AffinityBarrier(coordinator.get(), eventProcessor, affinityTimeout)));
    }
    asyncProcessing = true;
}
Also used : NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) MoreExecutors.newSequentialExecutor(com.google.common.util.concurrent.MoreExecutors.newSequentialExecutor) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 2 with NexusThreadFactory

use of org.sonatype.nexus.thread.NexusThreadFactory in project nexus-public by sonatype.

the class DatabaseBackupTask method makeExecutorService.

private ExecutorService makeExecutorService() {
    BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(MAX_QUEUED_BACKUPS);
    ThreadFactory factory = new NexusThreadFactory("dbbackup", "dbbackup");
    ThreadPoolExecutor backing = new ThreadPoolExecutor(MAX_CONCURRENT_BACKUPS, MAX_CONCURRENT_BACKUPS, 1, TimeUnit.NANOSECONDS, queue, factory);
    backing.allowCoreThreadTimeOut(true);
    return NexusExecutorService.forFixedSubject(backing, FakeAlmightySubject.TASK_SUBJECT);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 3 with NexusThreadFactory

use of org.sonatype.nexus.thread.NexusThreadFactory in project nexus-public by sonatype.

the class SearchEventHandler method doStart.

@Override
protected void doStart() throws Exception {
    if (flushOnCount > 1) {
        periodicJobService.startUsing();
        flushTask = periodicJobService.schedule(this::pollSearchUpdateRequest, flushOnSeconds);
    }
    this.threadPoolExecutor = new ThreadPoolExecutor(// core-size
    poolSize, // max-size
    poolSize, // keep-alive
    0L, TimeUnit.MILLISECONDS, // allow queueing up of requests
    new LinkedBlockingQueue<>(), new NexusThreadFactory("searchEventHandler", "flushAndPurge", MIN_PRIORITY), new AbortPolicy());
}
Also used : NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) AbortPolicy(java.util.concurrent.ThreadPoolExecutor.AbortPolicy) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 4 with NexusThreadFactory

use of org.sonatype.nexus.thread.NexusThreadFactory in project nexus-public by sonatype.

the class StreamCopier method makeExecutorService.

private static ExecutorService makeExecutorService() {
    final String name = StreamCopier.class.getSimpleName().toLowerCase();
    final int nThreads = getInteger(join(".", "nexus", name, "poolSize"), DEFAULT_POOL_SIZE);
    ThreadFactory factory = new NexusThreadFactory(name, name);
    ThreadPoolExecutor backing = new ThreadPoolExecutor(0, nThreads, 60L, SECONDS, new SynchronousQueue<>(), factory);
    return forFixedSubject(backing, TASK_SUBJECT);
}
Also used : NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) NexusThreadFactory(org.sonatype.nexus.thread.NexusThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 NexusThreadFactory (org.sonatype.nexus.thread.NexusThreadFactory)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 MoreExecutors.newSequentialExecutor (com.google.common.util.concurrent.MoreExecutors.newSequentialExecutor)1 Executor (java.util.concurrent.Executor)1 AbortPolicy (java.util.concurrent.ThreadPoolExecutor.AbortPolicy)1