javax.enterprise.concurrent.ManagedThreadFactory Java Examples

The following examples show how to use javax.enterprise.concurrent.ManagedThreadFactory. 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: ManagedExecutorServiceImplFactory.java    From tomee with Apache License 2.0 6 votes vote down vote up
private ExecutorService createExecutorService() {
    final BlockingQueue<Runnable> blockingQueue;
    if (queue <= 0) {
        blockingQueue = new LinkedBlockingQueue<>();
    } else {
        blockingQueue = new ArrayBlockingQueue<>(queue);
    }

    ManagedThreadFactory managedThreadFactory;
    try {
        managedThreadFactory = "org.apache.openejb.threads.impl.ManagedThreadFactoryImpl".equals(threadFactory) ?
                new ManagedThreadFactoryImpl() :
                ThreadFactories.findThreadFactory(threadFactory);
    } catch (final Exception e) {
        Logger.getInstance(LogCategory.OPENEJB, ManagedExecutorServiceImplFactory.class).warning("Can't create configured thread factory: " + threadFactory, e);
        managedThreadFactory = new ManagedThreadFactoryImpl();
    }

    return new ThreadPoolExecutor(core, max, keepAlive.getTime(), keepAlive.getUnit(), blockingQueue, managedThreadFactory, CURejectHandler.INSTANCE);
}
 
Example #2
Source File: CustomInjectionTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses, final ManagedThreadFactory tf) {
    assertNotNull(es);
    assertNotNull(ses);
    assertNotNull(tf);

    assertThat(es, instanceOf(ManagedExecutorServiceImpl.class));
    assertEquals(2, pool(es).getCorePoolSize());
    assertEquals(10, pool(es).getMaximumPoolSize());
    assertEquals(4, pool(es).getKeepAliveTime(TimeUnit.MINUTES));

    assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class));
    assertEquals(12, pool(ses).getCorePoolSize());

    assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class));
    assertEquals("custom-", Reflections.get(tf, "prefix"));
}
 
Example #3
Source File: HelloWebSocketEndpoint.java    From java-course-ee with MIT License 5 votes vote down vote up
public HelloWebSocketEndpoint() {
    log.debug("new HelloWebSocketEndpoint()");
    try {
        InitialContext context = new InitialContext();
        managedThreadFactory = (ManagedThreadFactory) context.lookup("java:jboss/ee/concurrency/factory/default");
    } catch (NamingException e) {
        e.printStackTrace();
    }
}
 
Example #4
Source File: ThreadFactories.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static ManagedThreadFactory findThreadFactory(final String threadFactory)
        throws InstantiationException, IllegalAccessException, NamingException {
    try {
        final Class<?> aClass = Thread.currentThread().getContextClassLoader().loadClass(threadFactory);
        if (!ManagedThreadFactory.class.isAssignableFrom(aClass) && ThreadFactory.class.isAssignableFrom(aClass)) {
            return new ManageMyThreadFactory(ThreadFactory.class.cast(aClass.newInstance()));
        }
        return ManagedThreadFactory.class.cast(aClass.newInstance());
    } catch (final ClassNotFoundException e) {
        return ManagedThreadFactory.class.cast(SystemInstance.get().getComponent(ContainerSystem.class)
                .getJNDIContext().lookup("openejb:Resource/" + threadFactory));
    }
}
 
Example #5
Source File: ManagedScheduledExecutorServiceImplFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
private ScheduledExecutorService createScheduledExecutorService() {
    ManagedThreadFactory managedThreadFactory;
    try {
        managedThreadFactory = ThreadFactories.findThreadFactory(threadFactory);
    } catch (final Exception e) {
        Logger.getInstance(LogCategory.OPENEJB, ManagedScheduledExecutorServiceImplFactory.class).warning("Unable to create configured thread factory: " + threadFactory, e);
        managedThreadFactory = new ManagedThreadFactoryImpl();
    }

    return new ScheduledThreadPoolExecutor(core, managedThreadFactory, CURejectHandler.INSTANCE);
}
 
Example #6
Source File: BuiltInEnvironmentEntries.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void add(final JndiConsumer jndi, final DeploymentModule module, final DeploymentModule app, final boolean defaults) {

        // Standard names
        add(jndi.getEnvEntryMap(), new EnvEntry().name("java:module/ModuleName").value(module.getModuleId()).type(String.class));
        add(jndi.getEnvEntryMap(), new EnvEntry().name("java:app/AppName").value(app.getModuleId()).type(String.class));

        // Standard References to built-in objects
        add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/BeanManager").type(BeanManager.class));
        add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/Validator").type(Validator.class));
        add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/ValidatorFactory").type(ValidatorFactory.class));
        add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionManager").type(TransactionManager.class));
        add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/TransactionSynchronizationRegistry").type(TransactionSynchronizationRegistry.class));

        if (defaults) {
            add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedExecutorService").type(ManagedExecutorService.class));
            add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedScheduledExecutorService").type(ManagedScheduledExecutorService.class));
            add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultManagedThreadFactory").type(ManagedThreadFactory.class));
            add(jndi.getResourceEnvRefMap(), new ResourceEnvRef().name("java:comp/DefaultContextService").type(ContextService.class));
            try {
                final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                contextClassLoader.loadClass("org.apache.activemq.ActiveMQSslConnectionFactory");
                final ResourceEnvRef ref = new ResourceEnvRef().name("java:comp/DefaultJMSConnectionFactory")
                    .type(contextClassLoader.loadClass("javax.jms.ConnectionFactory"));
                add(jndi.getResourceEnvRefMap(), ref);
            } catch (final ClassNotFoundException | NoClassDefFoundError notThere) {
                // no-op
            }
        }


        // OpenEJB specific feature
        add(jndi.getEnvEntryMap(), new EnvEntry().name("java:comp/ComponentName").value(jndi.getJndiConsumerName()).type(String.class));

    }
 
Example #7
Source File: InjectionTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static void doCheck(final ManagedExecutorService es, final ManagedScheduledExecutorService ses,
                            final ContextService ces, final ManagedThreadFactory tf) {
    assertNotNull(es);
    assertNotNull(ses);
    assertNotNull(ces);
    assertNotNull(tf);

    assertThat(es, instanceOf(ManagedExecutorServiceImpl.class));
    assertThat(ses, instanceOf(ManagedScheduledExecutorServiceImpl.class));
    assertThat(ces, instanceOf(ContextServiceImpl.class));
    assertThat(tf, instanceOf(ManagedThreadFactoryImpl.class));
}
 
Example #8
Source File: ManagedAsyncJobExecutor.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ManagedThreadFactory getThreadFactory() {
  return threadFactory;
}
 
Example #9
Source File: ManagedAsyncJobExecutor.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public void setThreadFactory(ManagedThreadFactory threadFactory) {
  this.threadFactory = threadFactory;
}
 
Example #10
Source File: ManagedAsyncJobExecutor.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public ManagedThreadFactory getThreadFactory() {
    return threadFactory;
}
 
Example #11
Source File: ManagedAsyncJobExecutor.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void setThreadFactory(ManagedThreadFactory threadFactory) {
    this.threadFactory = threadFactory;
}
 
Example #12
Source File: ManagedThreadFactoryExposerMock.java    From porcupine with Apache License 2.0 4 votes vote down vote up
@Produces
public ManagedThreadFactory expose() {
    return (r) -> newThread(r);
}
 
Example #13
Source File: CustomThreadFactoryExposer.java    From porcupine with Apache License 2.0 4 votes vote down vote up
@Produces
public ManagedThreadFactory expose() {
    return (r) -> newThread(r);
}
 
Example #14
Source File: ManagedThreadFactoryImplFactory.java    From tomee with Apache License 2.0 4 votes vote down vote up
public ManagedThreadFactory create() {
    return new ManagedThreadFactoryImpl(prefix);
}