org.jboss.threads.JBossThreadFactory Java Examples

The following examples show how to use org.jboss.threads.JBossThreadFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Execution.java    From quarkus with Apache License 2.0 6 votes vote down vote up
Execution(final BuildExecutionBuilder builder, final Set<ItemId> finalIds) {
    chain = builder.getChain();
    this.singles = new ConcurrentHashMap<>(builder.getInitialSingle());
    this.multis = new ConcurrentHashMap<>(builder.getInitialMulti());
    this.finalIds = finalIds;
    final EnhancedQueueExecutor.Builder executorBuilder = new EnhancedQueueExecutor.Builder();
    executorBuilder.setCorePoolSize(8).setMaximumPoolSize(1024);
    executorBuilder.setExceptionHandler(JBossExecutors.loggingExceptionHandler());
    executorBuilder.setThreadFactory(new JBossThreadFactory(new ThreadGroup("build group"), Boolean.FALSE, null, "build-%t",
            JBossExecutors.loggingExceptionHandler(), null));
    buildTargetName = builder.getBuildTargetName();
    executor = executorBuilder.build();
    lastStepCount.set(builder.getChain().getEndStepCount());
    if (lastStepCount.get() == 0)
        done = true;
}
 
Example #2
Source File: JConsoleCLIPlugin.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ExecutorService createExecutor() {
    final ThreadGroup group = new ThreadGroup("management-client-thread");
    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
        public JBossThreadFactory run() {
            return new JBossThreadFactory(group, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null);
        }
    });
    return EnhancedQueueExecutor.DISABLE_HINT ?
        new ThreadPoolExecutor(2, DEFAULT_MAX_THREADS, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), threadFactory) :
        new EnhancedQueueExecutor.Builder()
            .setCorePoolSize(2)
            .setMaximumPoolSize(DEFAULT_MAX_THREADS)
            .setKeepAliveTime(60, TimeUnit.SECONDS)
            .setThreadFactory(threadFactory)
            .build();
}
 
Example #3
Source File: ModelControllerClientConfiguration.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static ExecutorService createDefaultExecutor() {
    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
        public JBossThreadFactory run() {
            return new JBossThreadFactory(defaultThreadGroup, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null);
        }
    });
    final int maxThreads = getSystemProperty("org.jboss.as.controller.client.max-threads", 6);
    return EnhancedQueueExecutor.DISABLE_HINT ?
        new ThreadPoolExecutor(2, maxThreads, 60, TimeUnit.SECONDS, new LinkedBlockingDeque<>(), threadFactory) :
        new EnhancedQueueExecutor.Builder()
            .setCorePoolSize(2)
            .setMaximumPoolSize(maxThreads)
            .setKeepAliveTime(60, TimeUnit.SECONDS)
            .setThreadFactory(threadFactory)
            .build();
}
 
Example #4
Source File: ExternalManagementRequestExecutor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public synchronized void start(StartContext context) throws StartException {
    final String namePattern = "External Management Request Threads -- %t";
    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
        public ThreadFactory run() {
            return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
        }
    });

    int poolSize = getPoolSize();
    if (EnhancedQueueExecutor.DISABLE_HINT) {
        final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(WORK_QUEUE_SIZE);
        executorService = new ThreadPoolExecutor(poolSize, poolSize, 60L, TimeUnit.SECONDS,
                workQueue, threadFactory);
    } else {
        executorService = new EnhancedQueueExecutor.Builder()
            .setCorePoolSize(poolSize)
            .setMaximumPoolSize(poolSize)
            .setKeepAliveTime(60L, TimeUnit.SECONDS)
            .setMaximumQueueSize(WORK_QUEUE_SIZE)
            .setThreadFactory(threadFactory)
            .build();
    }
}
 
Example #5
Source File: DeploymentMountProvider.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void start(StartContext context) throws StartException {
    try {
        final JBossThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
            public JBossThreadFactory run() {
                return new JBossThreadFactory(new ThreadGroup("ServerDeploymentRepository-temp-threads"), true, null, "%G - %t", null, null);
            }
        });
        scheduledExecutorService =  Executors.newScheduledThreadPool(2, threadFactory);
        tempFileProvider = TempFileProvider.create("temp", scheduledExecutorService, true);
        deploymentMountProviderConsumer.accept(this);
    } catch (IOException e) {
        throw ServerLogger.ROOT_LOGGER.failedCreatingTempProvider(e);
    }
    ServerLogger.ROOT_LOGGER.debugf("%s started", DeploymentMountProvider.class.getSimpleName());
}
 
Example #6
Source File: RemoteChannelPairSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void setupRemoting(final ManagementChannelInitialization initialization) throws IOException {
    //executorService = Executors.newCachedThreadPool();
    final ThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("Remoting"), Boolean.FALSE, null, "Remoting %f thread %t", null, null);
    executorService = new QueueExecutor(EXECUTOR_MAX_THREADS / 4 + 1, EXECUTOR_MAX_THREADS, EXECUTOR_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS, 500, threadFactory, true, null);

    final ChannelServer.Configuration configuration = new ChannelServer.Configuration();
    configuration.setEndpointName(ENDPOINT_NAME);
    configuration.setUriScheme(URI_SCHEME);
    configuration.setBindAddress(new InetSocketAddress("127.0.0.1", PORT));
    configuration.setExecutor(executorService);
    channelServer = ChannelServer.create(configuration);

    channelServer.addChannelOpenListener(TEST_CHANNEL, new OpenListener() {

        @Override
        public void registrationTerminated() {
        }

        @Override
        public void channelOpened(Channel channel) {
            serverChannel = channel;
            initialization.startReceiving(channel);
            clientConnectedLatch.countDown();
        }
    });
}
 
Example #7
Source File: ExecutorRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static EnhancedQueueExecutor createExecutor(ThreadPoolConfig threadPoolConfig) {
    final JBossThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("executor"), Boolean.TRUE, null,
            "executor-thread-%t", JBossExecutors.loggingExceptionHandler("org.jboss.executor.uncaught"), null);
    final EnhancedQueueExecutor.Builder builder = new EnhancedQueueExecutor.Builder()
            .setRegisterMBean(false)
            .setHandoffExecutor(JBossExecutors.rejectingExecutor())
            .setThreadFactory(JBossExecutors.resettingThreadFactory(threadFactory));
    final int cpus = ProcessorInfo.availableProcessors();
    // run time config variables
    builder.setCorePoolSize(threadPoolConfig.coreThreads);
    builder.setMaximumPoolSize(threadPoolConfig.maxThreads.orElse(Math.max(8 * cpus, 200)));
    if (threadPoolConfig.queueSize.isPresent()) {
        if (threadPoolConfig.queueSize.getAsInt() < 0) {
            builder.setMaximumQueueSize(Integer.MAX_VALUE);
        } else {
            builder.setMaximumQueueSize(threadPoolConfig.queueSize.getAsInt());
        }
    }
    builder.setGrowthResistance(threadPoolConfig.growthResistance);
    builder.setKeepAliveTime(threadPoolConfig.keepAliveTime);
    return builder.build();
}
 
Example #8
Source File: DomainModelControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void start(StartContext context) throws StartException {
    final ExecutorService executorService = getExecutorService();
    this.hostControllerConfigurationPersister = new HostControllerConfigurationPersister(environment, hostControllerInfo, executorService, hostExtensionRegistry, extensionRegistry);
    setConfigurationPersister(hostControllerConfigurationPersister);
    prepareStepHandler.setExecutorService(executorService);
    ThreadFactory pingerThreadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
        public JBossThreadFactory run() {
            return new JBossThreadFactory(new ThreadGroup("proxy-pinger-threads"), Boolean.TRUE, null, "%G - %t", null, null);
        }
    });
    pingScheduler = Executors.newScheduledThreadPool(PINGER_POOL_SIZE, pingerThreadFactory);

    ContentCleanerService.addServiceOnHostController(context.getChildTarget(), DomainModelControllerService.SERVICE_NAME,
            CLIENT_FACTORY_SERVICE_NAME, HC_EXECUTOR_SERVICE_NAME, HC_SCHEDULED_EXECUTOR_SERVICE_NAME);

    super.start(context);

    pingScheduler.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                slaveHostRegistrations.pruneExpired();
            } catch (Exception e) {
                HostControllerLogger.DOMAIN_LOGGER.debugf(e, "failed to execute eviction task");
            }
        }
    }, 1, 1, TimeUnit.MINUTES);

}
 
Example #9
Source File: AbstractModelControllerOperationHandlerFactoryService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public synchronized void start(StartContext context) throws StartException {
    MGMT_OP_LOGGER.debugf("Starting operation handler service %s", context.getController().getName());
    responseAttachmentSupport = new ResponseAttachmentInputStreamSupport(scheduledExecutorSupplier.get());

    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() {
        public JBossThreadFactory run() {
            return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null);
        }
    });
    if (EnhancedQueueExecutor.DISABLE_HINT) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(POOL_CORE_SIZE, POOL_MAX_SIZE,
            600L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(WORK_QUEUE_SIZE),
            threadFactory);
        // Allow the core threads to time out as well
        executor.allowCoreThreadTimeOut(true);
        this.clientRequestExecutor = executor;
    } else {
        this.clientRequestExecutor = new EnhancedQueueExecutor.Builder()
        .setCorePoolSize(POOL_CORE_SIZE)
        .setMaximumPoolSize(POOL_MAX_SIZE)
        .setKeepAliveTime(600L, TimeUnit.SECONDS)
        .setMaximumQueueSize(WORK_QUEUE_SIZE)
        .setThreadFactory(threadFactory)
        .allowCoreThreadTimeOut(true)
        .build();
    }
    serviceConsumer.accept(this);
}
 
Example #10
Source File: ModelControllerClientTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelControllerClient setupTestClient(final ModelController controller) throws IOException {
    try {
        channels.setupRemoting(new ManagementChannelInitialization() {
            @Override
            public ManagementChannelHandler startReceiving(Channel channel) {
                final ManagementClientChannelStrategy strategy = ManagementClientChannelStrategy.create(channel);
                final ManagementChannelHandler support = new ManagementChannelHandler(strategy, channels.getExecutorService());
                support.addHandlerFactory(new ModelControllerClientOperationHandler(controller, support, new ResponseAttachmentInputStreamSupport(), getClientRequestExecutor()));
                channel.receiveMessage(support.getReceiver());
                return support;
            }

            private ExecutorService getClientRequestExecutor() {
                final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(512);
                final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
                    public ThreadFactory run() {
                        return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null);
                    }
                });
                ThreadPoolExecutor executor = new ThreadPoolExecutor(4, 4,
                        250L, TimeUnit.MILLISECONDS, workQueue,
                        threadFactory);
                // Allow the core threads to time out as well
                executor.allowCoreThreadTimeOut(true);
                return executor;
            }
        });
        channels.startClientConnetion();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final Channel clientChannel = channels.getClientChannel();
    return ExistingChannelModelControllerClient.createReceiving(clientChannel, channels.getExecutorService());
}
 
Example #11
Source File: DomainControllerClientConfig.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ExecutorService createDefaultExecutor() {
    final ThreadGroup group = new ThreadGroup("domain-mgmt-client-thread");
    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
        public ThreadFactory run() {
            return new JBossThreadFactory(group, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null);
        }
    });
    return new ThreadPoolExecutor(4, 4, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(256), threadFactory);
}
 
Example #12
Source File: RemoteChannelPairSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void setupRemoting(final ManagementMessageHandler handler) throws IOException {
    //executorService = new ThreadPoolExecutor(16, 16, 1L, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>());
    ThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("Remoting"), Boolean.FALSE, null, "Remoting %f thread %t", null, null);
    executorService = new QueueExecutor(EXECUTOR_MAX_THREADS / 4 + 1, EXECUTOR_MAX_THREADS, EXECUTOR_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS, 500, threadFactory, true, null);

    ChannelServer.Configuration configuration = new ChannelServer.Configuration();
    configuration.setEndpointName(ENDPOINT_NAME);
    configuration.setUriScheme(URI_SCHEME);
    configuration.setBindAddress(new InetSocketAddress("127.0.0.1", PORT));
    configuration.setExecutor(executorService);
    channelServer = ChannelServer.create(configuration);

    final Channel.Receiver receiver = ManagementChannelReceiver.createDelegating(handler);

    this.registration = channelServer.addChannelOpenListener(TEST_CHANNEL, new OpenListener() {

        @Override
        public void registrationTerminated() {
        }

        @Override
        public void channelOpened(Channel channel) {
            serverChannel = channel;
            serverChannel.receiveMessage(receiver);
            clientConnectedLatch.countDown();
        }
    });
}
 
Example #13
Source File: DeploymentScannerAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static ScheduledExecutorService createScannerExecutorService() {
    final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
        public ThreadFactory run() {
            return new JBossThreadFactory(new ThreadGroup("DeploymentScanner-threads"), Boolean.FALSE, null, "%G - %t", null, null);
        }
    });
    return Executors.newScheduledThreadPool(2, threadFactory);
}
 
Example #14
Source File: ThreadFactoryGenerator.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
public static final ThreadFactory generateFactory(boolean daemon, String threadGroupName) {
    String namePattern = "%G-%t";
    UncaughtExceptionHandler uncaughtExceptionHandler = null;
    Integer initialPriority = null;
    Long stackSize = null;
    return new JBossThreadFactory(
            new ThreadGroup(threadGroupName),
            daemon,
            initialPriority,
            namePattern,
            uncaughtExceptionHandler,
            stackSize,
            null); // this last param is ignored according to docs.
    // see: https://github.com/jbossas/jboss-threads/blob/2.2/src/main/java/org/jboss/threads/JBossThreadFactory.java#L90
}
 
Example #15
Source File: ThreadFactoryService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public synchronized void start(final StartContext context) throws StartException {
    final ThreadGroup threadGroup = (threadGroupName != null) ? new ThreadGroup(threadGroupName) : null;
    value = doPrivileged(new PrivilegedAction<ThreadFactory>() {
        public ThreadFactory run() {
            return new JBossThreadFactory(threadGroup, Boolean.FALSE, priority, namePattern, null, null);
        }
    });
}
 
Example #16
Source File: ServerToHostOperationHandlerFactoryService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public JBossThreadFactory run() {
    return new JBossThreadFactory(new ThreadGroup("server-registration-threads"), Boolean.FALSE, null, "%G - %t", null, null);
}
 
Example #17
Source File: HostControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public JBossThreadFactory run() {
    return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, "%G - %t", null, null);
}
 
Example #18
Source File: TestControllerUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static ExecutorService createDefaultExecutor() {
    final ThreadGroup group = new ThreadGroup("mgmt-client-thread");
    final ThreadFactory threadFactory = new JBossThreadFactory(group, Boolean.FALSE, null, "%G " + executorCount.incrementAndGet() + "-%t", null, null);
    return new ThreadPoolExecutor(4, 4, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(256), threadFactory);
}
 
Example #19
Source File: TempFileProviderService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public JBossThreadFactory run() {
    return new JBossThreadFactory(new ThreadGroup("TempFileProviderService-temp-threads"), Boolean.TRUE, null, "%G - %t", null, null);
}
 
Example #20
Source File: ServerService.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
     * Add this service to the given service target.
     *  @param serviceTarget the service target
     * @param configuration the bootstrap configuration
     */
    public static void addService(final ServiceTarget serviceTarget, final Bootstrap.Configuration configuration,
                                  final ControlledProcessState processState, final BootstrapListener bootstrapListener,
                                  final RunningModeControl runningModeControl, final AbstractVaultReader vaultReader, final ManagedAuditLogger auditLogger,
                                  final DelegatingConfigurableAuthorizer authorizer, final ManagementSecurityIdentitySupplier securityIdentitySupplier,
                                  final SuspendController suspendController) {

        // Install Executor services
        final ThreadGroup threadGroup = new ThreadGroup("ServerService ThreadGroup");
        final String namePattern = "ServerService Thread Pool -- %t";
        final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<ThreadFactory>() {
            public ThreadFactory run() {
                return new JBossThreadFactory(threadGroup, Boolean.FALSE, null, namePattern, null, null);
            }
        });

        // TODO determine why QueuelessThreadPoolService makes boot take > 35 secs
//        final QueuelessThreadPoolService serverExecutorService = new QueuelessThreadPoolService(Integer.MAX_VALUE, false, new TimeSpec(TimeUnit.SECONDS, 5));
//        serverExecutorService.getThreadFactoryInjector().inject(threadFactory);
        final boolean forDomain = ProcessType.DOMAIN_SERVER == getProcessType(configuration.getServerEnvironment());
        final ServerExecutorService serverExecutorService = new ServerExecutorService(threadFactory, forDomain);
        serviceTarget.addService(MANAGEMENT_EXECUTOR, serverExecutorService)
                .addAliases(Services.JBOSS_SERVER_EXECUTOR, ManagementRemotingServices.SHUTDOWN_EXECUTOR_NAME) // Use this executor for mgmt shutdown for now
                .install();
        final ServerScheduledExecutorService serverScheduledExecutorService = new ServerScheduledExecutorService(threadFactory);
        serviceTarget.addService(JBOSS_SERVER_SCHEDULED_EXECUTOR, serverScheduledExecutorService)
                .addAliases(JBOSS_SERVER_SCHEDULED_EXECUTOR)
                .addDependency(MANAGEMENT_EXECUTOR, ExecutorService.class, serverScheduledExecutorService.executorInjector)
                .install();

        final CapabilityRegistry capabilityRegistry = configuration.getCapabilityRegistry();

        ServiceBuilder<?> serviceBuilder = serviceTarget.addService(Services.JBOSS_SERVER_CONTROLLER);
        final boolean allowMCE = configuration.getServerEnvironment().isAllowModelControllerExecutor();
        final Supplier<ExecutorService> esSupplier = allowMCE ? serviceBuilder.requires(MANAGEMENT_EXECUTOR) : null;
        final boolean isDomainEnv = configuration.getServerEnvironment().getLaunchType() == ServerEnvironment.LaunchType.DOMAIN;
        final Supplier<ControllerInstabilityListener> cilSupplier = isDomainEnv ? serviceBuilder.requires(HostControllerConnectionService.SERVICE_NAME) : null;
        ServerService service = new ServerService(esSupplier, cilSupplier, configuration, processState, null, bootstrapListener, new ServerDelegatingResourceDefinition(),
                runningModeControl, vaultReader, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, suspendController);
        serviceBuilder.setInstance(service);
        serviceBuilder.addDependency(DeploymentMountProvider.SERVICE_NAME,DeploymentMountProvider.class, service.injectedDeploymentRepository);
        serviceBuilder.addDependency(ContentRepository.SERVICE_NAME, ContentRepository.class, service.injectedContentRepository);
        serviceBuilder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.injectedModuleLoader);
        serviceBuilder.addDependency(EXTERNAL_MODULE_CAPABILITY.getCapabilityServiceName(), ExternalModule.class,
                service.injectedExternalModule);
        serviceBuilder.addDependency(PATH_MANAGER_CAPABILITY.getCapabilityServiceName(), PathManager.class, service.injectedPathManagerService);
        serviceBuilder.requires(CONSOLE_AVAILABILITY_CAPABILITY.getCapabilityServiceName());

        serviceBuilder.install();

        ExternalManagementRequestExecutor.install(serviceTarget, threadGroup, EXECUTOR_CAPABILITY.getCapabilityServiceName(), service.getStabilityMonitor());

    }