Examples of ManagedThreadFactory


Examples of javax.util.concurrent.ManagedThreadFactory

import junit.framework.TestCase;

public class ManagedThreadFactoryTest extends TestCase {
   
    private ManagedThreadFactory getManagedThreadFactory() {
        ManagedThreadFactory factory = new BasicManagedThreadFactory();
        ManagedContextHandlerChain chain = new ManagedContextHandlerChain();
        chain.addManagedContextHandler(new TestContextHandler());
        return ManagedThreadFactoryUtils.createStandaloneThreadFactory(factory, chain);   
    }
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

    }
             
    public void testCancel() throws Exception {
        BasicTask task = new BasicTask();
       
        ManagedThreadFactory threadFactory = getManagedThreadFactory();
       
        ManagedThread thread =
            (ManagedThread)threadFactory.newThread(task);
           
        thread.setHungTaskThreshold(1000 * 5);
       
        assertFalse(thread.isTaskHung());
       
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

                               task.getIdentityName(),
                               task.getIdentityDescription(Locale.getDefault()));
    }
   
    private void testExpectedProperties(Runnable task, String expectedName, String expectedDescription) throws Exception {
        ManagedThreadFactory threadFactory = getManagedThreadFactory();
       
        ManagedThread thread =
            (ManagedThread)threadFactory.newThread(task);
       
        assertNull(thread.getTaskIdentityDescription());
        assertNull(thread.getTaskIdentityDescription(Locale.getDefault().toString()));
        assertNull(thread.getTaskIdentityName());
        assertEquals(0, thread.getTaskRunTime());
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

        MyTask task = new MyTask();  
       
        String expected = "hello123ThreadFactory";
        TestContextHandler.setCurrentObject(expected);
       
        ManagedThreadFactory threadFactory = getManagedThreadFactory();
                       
        assertEquals(expected, TestContextHandler.getCurrentObject());
        TestContextHandler.setCurrentObject(null);
        assertNull(TestContextHandler.getCurrentObject());
       
        Thread thread = threadFactory.newThread(task);       
        thread.start();
        thread.join();
       
        assertEquals(Arrays.asList(expected), task.getList());       
    }
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

    }
   
    public void testContextMigration(boolean testEjbSecurity) throws Exception {
        // since ee context is captured on jndi lookup for ManagedThreadFactory
        // lookup ThreadFactory here to get the right security context
        ManagedThreadFactory threadFactory = getThreadFactory();

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        BasicTaskRunnable runnable = new BasicTaskRunnable(classLoader);
        runnable.setTestEjbSecurity(testEjbSecurity);
        RunnableWrapper wrapper = new RunnableWrapper(runnable);
        Thread t = threadFactory.newThread(wrapper);
        t.start();
        t.join();
       
        Throwable throwable = wrapper.getThrowable();
        if (throwable instanceof Exception) {
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

        }
    }
   
    private ManagedThreadFactory getThreadFactory() throws NamingException {
        InitialContext ctx = new InitialContext();
        ManagedThreadFactory threadFactory =
            (ManagedThreadFactory)ctx.lookup("java:comp/env/" + getClass().getName() + "/threadFactory");
        return threadFactory;
    }
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

    }
   
    public void testContextMigration(boolean testEjbSecurity) throws Exception {
        // since ee context is captured on jndi lookup for ManagedThreadFactory
        // lookup ThreadFactory here to get the right security context
        ManagedThreadFactory threadFactory = getThreadFactory();

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        BasicTaskRunnable runnable = new BasicTaskRunnable(classLoader);
        runnable.setTestEjbSecurity(testEjbSecurity);
        RunnableWrapper wrapper = new RunnableWrapper(runnable);
        Thread t = threadFactory.newThread(wrapper);
        t.start();
        t.join();
       
        Throwable throwable = wrapper.getThrowable();
        if (throwable instanceof Exception) {
View Full Code Here

Examples of javax.util.concurrent.ManagedThreadFactory

        }
    }
   
    private ManagedThreadFactory getThreadFactory() throws NamingException {
        InitialContext ctx = new InitialContext();
        ManagedThreadFactory threadFactory =
            (ManagedThreadFactory)ctx.lookup("java:comp/env/" + getClass().getName() + "/threadFactory");
        return threadFactory;
    }
View Full Code Here

Examples of org.glassfish.concurrent.config.ManagedThreadFactory

        enabledValueForTarget = (String) attributes.get(ENABLED);
    }

    private ManagedThreadFactory createResource(Resources param, Properties properties) throws PropertyVetoException,
            TransactionFailure {
        ManagedThreadFactory newResource = createConfigBean(param, properties);
        param.getResources().add(newResource);
        return newResource;
    }
View Full Code Here

Examples of org.glassfish.concurrent.config.ManagedThreadFactory

        return newResource;
    }

    private ManagedThreadFactory createConfigBean(Resources param, Properties properties) throws PropertyVetoException,
            TransactionFailure {
        ManagedThreadFactory managedThreadFactory = param.createChild(ManagedThreadFactory.class);
        managedThreadFactory.setJndiName(jndiName);
        if (description != null) {
            managedThreadFactory.setDescription(description);
        }
        managedThreadFactory.setContextInfoEnabled(contextInfoEnabled);
        managedThreadFactory.setContextInfo(contextInfo);
        managedThreadFactory.setThreadPriority(threadPriority);
        managedThreadFactory.setEnabled(enabled);
        if (properties != null) {
            for ( Map.Entry e : properties.entrySet()) {
                Property prop = managedThreadFactory.createChild(Property.class);
                prop.setName((String)e.getKey());
                prop.setValue((String)e.getValue());
                managedThreadFactory.getProperty().add(prop);
            }
        }
        return managedThreadFactory;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.