Example usage for java.lang Thread setContextClassLoader

List of usage examples for java.lang Thread setContextClassLoader

Introduction

In this page you can find the example usage for java.lang Thread setContextClassLoader.

Prototype

public void setContextClassLoader(ClassLoader cl) 

Source Link

Document

Sets the context ClassLoader for this Thread.

Usage

From source file:org.nuxeo.runtime.bridge.ApplicationManager.java

protected Application load(ApplicationDescriptor desc) throws Exception {
    log.info("Loading application: " + desc.getName());
    ApplicationFactory factory;//  w w  w .j  a va2s.c  om
    if (desc.isIsolated()) {
        IsolatedClassLoader cl = createIsolatedClassLoader(desc);
        factory = (ApplicationFactory) cl.loadClass(desc.getFactory()).newInstance();
        Thread th = Thread.currentThread();
        ClassLoader oldcl = th.getContextClassLoader();
        th.setContextClassLoader(cl);
        try {
            return factory.createApplication(desc);
        } finally {
            th.setContextClassLoader(oldcl);
        }
    } else {
        factory = (ApplicationFactory) desc.getBundle().loadClass(desc.getFactory()).newInstance();
        return factory.createApplication(desc);
    }
}

From source file:org.jboss.forge.addon.resource.monitor.FileMonitor.java

public FileMonitor() {
    alterationMonitor = new FileAlterationMonitor(CHECK_INTERVAL);
    alterationMonitor.setThreadFactory(new ThreadFactory() {
        @Override//  www  . ja v  a2s  . co  m
        public Thread newThread(Runnable r) {
            Thread resourceMonitorThread = new Thread(r, "Resource File Monitor");
            resourceMonitorThread.setDaemon(true);
            resourceMonitorThread.setContextClassLoader(null);
            return resourceMonitorThread;
        }
    });
}

From source file:org.nuxeo.runtime.jboss.deployer.Bootstrap.java

public void startNuxeo() throws Exception {
    Thread thread = Thread.currentThread();
    ClassLoader oldcl = thread.getContextClassLoader();
    thread.setContextClassLoader(cl);
    try {/*from   www . ja  v a  2 s. c o m*/
        doStart();
    } finally {
        thread.setContextClassLoader(oldcl);
    }
}

From source file:org.nuxeo.runtime.jboss.deployer.Bootstrap.java

public void stopNuxeo() throws Exception {
    Thread thread = Thread.currentThread();
    ClassLoader oldcl = thread.getContextClassLoader();
    thread.setContextClassLoader(cl);
    try {/*from  w ww  . j a  v a2s  . co m*/
        invokeStop();
    } finally {
        thread.setContextClassLoader(oldcl);
    }
}

From source file:org.springframework.boot.rsocket.netty.NettyRSocketServer.java

private void startDaemonAwaitThread(CloseableChannel channel) {
    Thread awaitThread = new Thread("rsocket") {

        @Override/*from w ww  .  j ava2s . c  o m*/
        public void run() {
            channel.onClose().block();
        }

    };
    awaitThread.setContextClassLoader(getClass().getClassLoader());
    awaitThread.setDaemon(false);
    awaitThread.start();
}

From source file:org.intalio.tempo.security.ws.BaseWS.java

protected void initStatics() {
    if (_initialized)
        return;/*from   w  ww.  j a va2 s  .  c om*/
    try {
        synchronized (BaseWS.class) {
            if (_initialized)
                return;
            LOG.debug("Initializing configuration.");
            String configDir = System.getProperty(Constants.CONFIG_DIR_PROPERTY);
            if (configDir == null) {
                throw new RuntimeException(
                        "System property " + Constants.CONFIG_DIR_PROPERTY + " not defined.");
            }
            _configDir = new File(configDir);
            if (!_configDir.exists()) {
                throw new RuntimeException(
                        "Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist.");
            }

            Thread thread = Thread.currentThread();
            ClassLoader oldClassLoader = thread.getContextClassLoader();
            try {
                thread.setContextClassLoader(getClass().getClassLoader());
                FileSystemResource config = new FileSystemResource(new File(_configDir, "securityConfig.xml"));
                XmlBeanFactory factory = new XmlBeanFactory(config);

                PropertyPlaceholderConfigurer propsCfg = new PropertyPlaceholderConfigurer();
                propsCfg.setSearchSystemEnvironment(true);
                propsCfg.postProcessBeanFactory(factory);
                _securityProvider = (SecurityProvider) factory.getBean("securityProvider");
                _tokenService = (org.intalio.tempo.security.token.TokenService) factory.getBean("tokenService");
                _initialized = true;
            } finally {
                thread.setContextClassLoader(oldClassLoader);
            }
        }
    } catch (RuntimeException except) {
        LOG.error("Error during initialization of security service", except);
        throw except;
    }
}

From source file:net.sf.jasperreports.ant.JavaflowRewriteTask.java

@Override
public void execute() throws BuildException {
    Thread thread = Thread.currentThread();
    ClassLoader originalClassLoader = thread.getContextClassLoader();
    try {//from   ww w  .j av  a 2  s.c o m
        //javaflow's ContinuationMethodAnalyzer uses the thread classloader to resolve classes
        thread.setContextClassLoader(getClass().getClassLoader());

        super.execute();
    } finally {
        thread.setContextClassLoader(originalClassLoader);
    }
}

From source file:org.nuxeo.ecm.core.persistence.PersistenceProvider.java

public <T> T run(Boolean needActiveSession, RunCallback<T> callback) throws ClientException {
    // needActiveSession now unused
    Thread myThread = Thread.currentThread();
    ClassLoader lastLoader = myThread.getContextClassLoader();
    myThread.setContextClassLoader(getClass().getClassLoader());
    try { // insure context class loader restoring
        EntityManager em = doAcquireEntityManager();
        doBegin(em);/*from   w w  w .j  a v  a 2  s . com*/
        try { // insure entity manager releasing
            return callback.runWith(em);
        } finally {
            releaseEntityManager(em);
        }
    } finally {
        myThread.setContextClassLoader(lastLoader);
    }
}

From source file:org.nuxeo.ecm.core.persistence.PersistenceProvider.java

public void run(Boolean needActiveSession, RunVoid callback) throws ClientException {
    // needActiveSession now unused
    Thread myThread = Thread.currentThread();
    ClassLoader lastLoader = myThread.getContextClassLoader();
    myThread.setContextClassLoader(getClass().getClassLoader());
    try { // insure context class loader restoring
        EntityManager em = doAcquireEntityManager();
        doBegin(em);//from   w w  w  . j a  v a 2  s  .c  om
        try { // insure entity manager releasing
            callback.runWith(em);
        } finally {
            releaseEntityManager(em);
        }
    } finally {
        myThread.setContextClassLoader(lastLoader);
    }
}

From source file:org.opennaas.extensions.bod.autobahn.protocol.AutobahnProtocolSession.java

private <T> T createSoapService(String uri, QName serviceName, QName portName, Class<T> clazz)
        throws ProtocolException {
    /*//  www . java  2 s .c  o m
     * The JAXWS SPI uses the context class loader to locate an implementation. We therefore make sure the context class loader is set to our
     * class loader.
     */
    Thread thread = Thread.currentThread();
    ClassLoader oldLoader = thread.getContextClassLoader();
    try {
        thread.setContextClassLoader(getClass().getClassLoader());
        Service service = Service.create(serviceName);
        service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, uri);
        return service.getPort(portName, clazz);
    } catch (WebServiceException e) {
        throw new ProtocolException("Failed to create Autobahn session: " + e.getMessage(), e);
    } finally {
        thread.setContextClassLoader(oldLoader);
    }
}