/** * Executes the provided {@link Runnable} implementation in the specified {@link ClassLoader}. * <p> * Utilises the {@link com.atlassian.plugin.util.ClassLoaderStack#push} method to save the old {@link ClassLoader} and * set the one specified as <code>newClassLoader</code>. {@link com.atlassian.plugin.util.ClassLoaderStack#pop} is * called in a finally block to ensure the {@link ClassLoader} is set back to the original one. * * @param newClassLoader The {@link ClassLoader} to run the specified {@link Runnable} in. * @param runnable The implementation to be run in the specified {@link ClassLoader} */ public static void runInContext(ClassLoader newClassLoader, Runnable runnable) { try { runInContext(newClassLoader, callable(runnable)); } catch (RuntimeException re) { throw re; } catch (Exception e) { // Do nothing, this can't happen } }
void loadHostComponents(final DefaultComponentRegistrar registrar) { // Unregister any existing host components if (hostServicesReferences != null) { for (final ServiceRegistration reg : hostServicesReferences) { reg.unregister(); } } ContextClassLoaderSwitchingUtil.runInContext(initializedClassLoader, () -> { hostServicesReferences = registrar.writeRegistry(bundleContext); hostComponentRegistrations = registrar.getRegistry(); }); }
ContextClassLoaderSwitchingUtil.runInContext(SyndFeed.class.getClassLoader(), rome); SyndFeed feed = rome.feed;