List of usage examples for java.beans Introspector flushCaches
public static void flushCaches()
From source file:eu.qualityontime.commons.QPropertyUtilsBean.java
/** * Clear any cached property descriptors information for all classes loaded * by any class loaders. This is useful in cases where class loaders are * thrown away to implement class reloading. *//*from w w w .j av a2 s . c om*/ public void clearDescriptors() { descriptorsCache.clear(); mappedDescriptorsCache.clear(); Introspector.flushCaches(); }
From source file:org.red5.server.war.RootContextLoaderServlet.java
/** * Clearing the in-memory configuration parameters, we will receive * notification that the servlet context is about to be shut down *///from ww w. j a v a2 s .co m @Override public void contextDestroyed(ServletContextEvent sce) { synchronized (instance) { logger.info("Webapp shutdown"); // XXX Paul: grabbed this from // http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go // in hopes that we can clear all the issues with J2EE containers // during shutdown try { ServletContext ctx = sce.getServletContext(); // if the ctx being destroyed is root then kill the timer if (ctx.getContextPath().equals("/ROOT")) { timer.cancel(); } else { // remove from registered list registeredContexts.remove(ctx); } // prepare spring for shutdown Introspector.flushCaches(); // dereg any drivers for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) { Driver driver = (Driver) e.nextElement(); if (driver.getClass().getClassLoader() == getClass().getClassLoader()) { DriverManager.deregisterDriver(driver); } } // shutdown jmx JMXAgent.shutdown(); // shutdown spring Object attr = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (attr != null) { // get web application context from the servlet context ConfigurableWebApplicationContext applicationContext = (ConfigurableWebApplicationContext) attr; ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); // for (String scope : factory.getRegisteredScopeNames()) { // logger.debug("Registered scope: " + scope); // } try { for (String singleton : factory.getSingletonNames()) { logger.debug("Registered singleton: " + singleton); factory.destroyScopedBean(singleton); } } catch (RuntimeException e) { } factory.destroySingletons(); ctx.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); applicationContext.close(); } instance.getContextLoader().closeWebApplicationContext(ctx); } catch (Throwable e) { e.printStackTrace(); } finally { // http://jakarta.apache.org/commons/logging/guide.html#Classloader_and_Memory_Management // http://wiki.apache.org/jakarta-commons/Logging/UndeployMemoryLeak?action=print LogFactory.release(Thread.currentThread().getContextClassLoader()); } } }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
public static void main(String[] args) throws Exception { Map<String, String> arguments = ArgumentsUtil.parseArguments(args); String apiDirName = arguments.get("service.api.dir"); boolean autoImportDefaultReferences = GetterUtil .getBoolean(arguments.get("service.auto.import.default.references"), true); boolean autoNamespaceTables = GetterUtil.getBoolean(arguments.get("service.auto.namespace.tables")); String beanLocatorUtil = arguments.get("service.bean.locator.util"); long buildNumber = GetterUtil.getLong(arguments.get("service.build.number"), 1); boolean buildNumberIncrement = GetterUtil.getBoolean(arguments.get("service.build.number.increment"), true); String hbmFileName = arguments.get("service.hbm.file"); String implDirName = arguments.get("service.impl.dir"); String inputFileName = arguments.get("service.input.file"); String[] modelHintsConfigs = StringUtil .split(GetterUtil.getString(arguments.get("service.model.hints.configs"), StringUtil.merge(ServiceBuilderArgs.MODEL_HINTS_CONFIGS))); String modelHintsFileName = arguments.get("service.model.hints.file"); boolean osgiModule = GetterUtil.getBoolean(arguments.get("service.osgi.module")); String pluginName = arguments.get("service.plugin.name"); String propsUtil = arguments.get("service.props.util"); String[] readOnlyPrefixes = StringUtil .split(GetterUtil.getString(arguments.get("service.read.only.prefixes"), StringUtil.merge(ServiceBuilderArgs.READ_ONLY_PREFIXES))); String remotingFileName = arguments.get("service.remoting.file"); String[] resourceActionsConfigs = StringUtil .split(GetterUtil.getString(arguments.get("service.resource.actions.configs"), StringUtil.merge(ServiceBuilderArgs.RESOURCE_ACTION_CONFIGS))); String resourcesDirName = arguments.get("service.resources.dir"); String springFileName = arguments.get("service.spring.file"); String[] springNamespaces = StringUtil.split(arguments.get("service.spring.namespaces")); String sqlDirName = arguments.get("service.sql.dir"); String sqlFileName = arguments.get("service.sql.file"); String sqlIndexesFileName = arguments.get("service.sql.indexes.file"); String sqlSequencesFileName = arguments.get("service.sql.sequences.file"); String targetEntityName = arguments.get("service.target.entity.name"); String testDirName = arguments.get("service.test.dir"); Set<String> resourceActionModels = readResourceActionModels(implDirName, resourceActionsConfigs); ModelHintsUtil modelHintsUtil = new ModelHintsUtil(); ModelHintsImpl modelHintsImpl = new ModelHintsImpl(); modelHintsImpl.setModelHintsConfigs(modelHintsConfigs); modelHintsImpl.afterPropertiesSet(); modelHintsUtil.setModelHints(modelHintsImpl); try {// w ww. j a va 2s . c o m ServiceBuilder serviceBuilder = new ServiceBuilder(apiDirName, autoImportDefaultReferences, autoNamespaceTables, beanLocatorUtil, buildNumber, buildNumberIncrement, hbmFileName, implDirName, inputFileName, modelHintsFileName, osgiModule, pluginName, propsUtil, readOnlyPrefixes, remotingFileName, resourceActionModels, resourcesDirName, springFileName, springNamespaces, sqlDirName, sqlFileName, sqlIndexesFileName, sqlSequencesFileName, targetEntityName, testDirName, true); String modifiedFileNames = StringUtil.merge(serviceBuilder.getModifiedFileNames()); System.setProperty(ServiceBuilderArgs.OUTPUT_KEY_MODIFIED_FILES, modifiedFileNames); } catch (Throwable t) { String message = "Please set these arguments. Sample values are:\n" + "\n" + "\tservice.api.dir=${basedir}/../portal-service/src\n" + "\tservice.auto.import.default.references=true\n" + "\tservice.auto.namespace.tables=false\n" + "\tservice.bean.locator.util=com.liferay.portal.kernel.bean.PortalBeanLocatorUtil\n" + "\tservice.build.number=1\n" + "\tservice.build.number.increment=true\n" + "\tservice.hbm.file=${basedir}/src/META-INF/portal-hbm.xml\n" + "\tservice.impl.dir=${basedir}/src\n" + "\tservice.input.file=${service.file}\n" + "\tservice.model.hints.configs=" + StringUtil.merge(ServiceBuilderArgs.MODEL_HINTS_CONFIGS) + "\n" + "\tservice.model.hints.file=${basedir}/src/META-INF/portal-model-hints.xml\n" + "\tservice.osgi.module=false\n" + "\tservice.plugin.name=\n" + "\tservice.props.util=com.liferay.portal.util.PropsUtil\n" + "\tservice.read.only.prefixes=" + StringUtil.merge(ServiceBuilderArgs.READ_ONLY_PREFIXES) + "\n" + "\tservice.remoting.file=${basedir}/../portal-web/docroot/WEB-INF/remoting-servlet.xml\n" + "\tservice.resource.actions.configs=" + StringUtil.merge(ServiceBuilderArgs.RESOURCE_ACTION_CONFIGS) + "\n" + "\tservice.resources.dir=${basedir}/src\n" + "\tservice.spring.file=${basedir}/src/META-INF/portal-spring.xml\n" + "\tservice.spring.namespaces=beans\n" + "\tservice.sql.dir=${basedir}/../sql\n" + "\tservice.sql.file=portal-tables.sql\n" + "\tservice.sql.indexes.file=indexes.sql\n" + "\tservice.sql.sequences.file=sequences.sql\n" + "\tservice.target.entity.name=${service.target.entity.name}\n" + "\tservice.test.dir=${basedir}/test/integration\n" + "\n" + "You can also customize the generated code by overriding the default templates with these optional system properties:\n" + "\n" + "\t-Dservice.tpl.bad_alias_names=" + _TPL_ROOT + "bad_alias_names.txt\n" + "\t-Dservice.tpl.bad_column_names=" + _TPL_ROOT + "bad_column_names.txt\n" + "\t-Dservice.tpl.bad_json_types=" + _TPL_ROOT + "bad_json_types.txt\n" + "\t-Dservice.tpl.bad_table_names=" + _TPL_ROOT + "bad_table_names.txt\n" + "\t-Dservice.tpl.base_mode_impl=" + _TPL_ROOT + "base_mode_impl.ftl\n" + "\t-Dservice.tpl.blob_model=" + _TPL_ROOT + "blob_model.ftl\n" + "\t-Dservice.tpl.copyright.txt=copyright.txt\n" + "\t-Dservice.tpl.ejb_pk=" + _TPL_ROOT + "ejb_pk.ftl\n" + "\t-Dservice.tpl.exception=" + _TPL_ROOT + "exception.ftl\n" + "\t-Dservice.tpl.export_actionable_dynamic_query=" + _TPL_ROOT + "export_actionable_dynamic_query.ftl\n" + "\t-Dservice.tpl.extended_model=" + _TPL_ROOT + "extended_model.ftl\n" + "\t-Dservice.tpl.extended_model_base_impl=" + _TPL_ROOT + "extended_model_base_impl.ftl\n" + "\t-Dservice.tpl.extended_model_impl=" + _TPL_ROOT + "extended_model_impl.ftl\n" + "\t-Dservice.tpl.finder=" + _TPL_ROOT + "finder.ftl\n" + "\t-Dservice.tpl.finder_util=" + _TPL_ROOT + "finder_util.ftl\n" + "\t-Dservice.tpl.hbm_xml=" + _TPL_ROOT + "hbm_xml.ftl\n" + "\t-Dservice.tpl.json_js=" + _TPL_ROOT + "json_js.ftl\n" + "\t-Dservice.tpl.json_js_method=" + _TPL_ROOT + "json_js_method.ftl\n" + "\t-Dservice.tpl.model=" + _TPL_ROOT + "model.ftl\n" + "\t-Dservice.tpl.model_cache=" + _TPL_ROOT + "model_cache.ftl\n" + "\t-Dservice.tpl.model_hints_xml=" + _TPL_ROOT + "model_hints_xml.ftl\n" + "\t-Dservice.tpl.model_impl=" + _TPL_ROOT + "model_impl.ftl\n" + "\t-Dservice.tpl.model_soap=" + _TPL_ROOT + "model_soap.ftl\n" + "\t-Dservice.tpl.model_wrapper=" + _TPL_ROOT + "model_wrapper.ftl\n" + "\t-Dservice.tpl.persistence=" + _TPL_ROOT + "persistence.ftl\n" + "\t-Dservice.tpl.persistence_impl=" + _TPL_ROOT + "persistence_impl.ftl\n" + "\t-Dservice.tpl.persistence_util=" + _TPL_ROOT + "persistence_util.ftl\n" + "\t-Dservice.tpl.props=" + _TPL_ROOT + "props.ftl\n" + "\t-Dservice.tpl.remoting_xml=" + _TPL_ROOT + "remoting_xml.ftl\n" + "\t-Dservice.tpl.service=" + _TPL_ROOT + "service.ftl\n" + "\t-Dservice.tpl.service_base_impl=" + _TPL_ROOT + "service_base_impl.ftl\n" + "\t-Dservice.tpl.service_clp=" + _TPL_ROOT + "service_clp.ftl\n" + "\t-Dservice.tpl.service_clp_invoker=" + _TPL_ROOT + "service_clp_invoker.ftl\n" + "\t-Dservice.tpl.service_clp_message_listener=" + _TPL_ROOT + "service_clp_message_listener.ftl\n" + "\t-Dservice.tpl.service_clp_serializer=" + _TPL_ROOT + "service_clp_serializer.ftl\n" + "\t-Dservice.tpl.service_http=" + _TPL_ROOT + "service_http.ftl\n" + "\t-Dservice.tpl.service_impl=" + _TPL_ROOT + "service_impl.ftl\n" + "\t-Dservice.tpl.service_props_util=" + _TPL_ROOT + "service_props_util.ftl\n" + "\t-Dservice.tpl.service_soap=" + _TPL_ROOT + "service_soap.ftl\n" + "\t-Dservice.tpl.service_util=" + _TPL_ROOT + "service_util.ftl\n" + "\t-Dservice.tpl.service_wrapper=" + _TPL_ROOT + "service_wrapper.ftl\n" + "\t-Dservice.tpl.spring_xml=" + _TPL_ROOT + "spring_xml.ftl\n" + "\t-Dservice.tpl.spring_xml_session=" + _TPL_ROOT + "spring_xml_session.ftl"; if (t instanceof ServiceBuilderException) { ServiceBuilderException serviceBuilderException = (ServiceBuilderException) t; System.err.println(serviceBuilderException.getMessage()); } else if (t instanceof Exception) { System.out.println(message); ArgumentsUtil.processMainException(arguments, (Exception) t); } else { t.printStackTrace(); } } try { ClearThreadLocalUtil.clearThreadLocal(); } catch (Throwable t) { t.printStackTrace(); } Introspector.flushCaches(); }
From source file:de.suse.swamp.core.api.WorkflowAPI.java
public long doFullgc(String uname) throws StorageException, SecurityException, UnknownElementException { if (!SecurityManager.isGroupMember(SecurityManager.getUser(uname), "swampadmins")) { throw new SecurityException("Not allowed to do a full GC()."); }/*from w ww. ja va2 s .c om*/ Runtime.getRuntime().gc(); Runtime.getRuntime().gc(); Introspector.flushCaches(); long freeMem2 = Runtime.getRuntime().freeMemory() / 1024l / 1024l; return freeMem2; }
From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java
/** * Run the matrix model.//w ww . j av a2s . com * * @return the double */ public Double runMatrixModel() { // Create a results holder. Double results = Double.NaN; // Attempt to run the model. try { // Setup a temporary class loader. URL[] urls = new URL[] { new File(Util.TEMP_DIR).toURI().toURL() }; URLClassLoader classLoader = new URLClassLoader(urls, null, null); // Attempt to load the compiled file. @SuppressWarnings("rawtypes") Constructor constructor = classLoader .loadClass(MatrixModel.PACKAGE_NAME + "." + MatrixModel.CONCRETE_CLASS_NAME) .getDeclaredConstructor(double.class); constructor.setAccessible(true); Object object = constructor.newInstance(this.stepSize); // Call "matrixFormulation.step(steps)". Method method = object.getClass().getSuperclass().getMethod("step", int.class); method.invoke(object, this.stepCount); // Call matrixFormulation.calculateFitnessValue(); method = object.getClass().getSuperclass().getMethod("calculateFitnessValue"); results = (Double) method.invoke(object); // Clear the given class loader, which should not be // a child of another class loader. object = null; method = null; classLoader.close(); ResourceBundle.clearCache(classLoader); classLoader = null; Introspector.flushCaches(); System.runFinalization(); System.gc(); // Catch exceptions. } catch (Exception e) { // Return the default result. results = Double.NaN; } // Return the results. return results; }
From source file:org.allcolor.yahp.converter.CClassLoader.java
/** * destroy the loader tree/*from w ww . j av a 2s. c o m*/ */ public static final void destroy() { if (CClassLoader.rootLoader == null) { return; } System.out.println("Destroying YAHP ClassLoader Tree"); CClassLoader.urlLoader = null; try { Field f = Class.forName("java.lang.Shutdown").getDeclaredField("hooks"); f.setAccessible(true); ArrayList l = (ArrayList) f.get(null); for (Iterator it = l.iterator(); it.hasNext();) { Object o = it.next(); if ((o != null) && (o.getClass().getClassLoader() != null) && (o.getClass().getClassLoader().getClass() == CClassLoader.class)) { it.remove(); } } } catch (Throwable ignore) { } try { Field f = Class.forName("java.lang.ApplicationShutdownHooks").getDeclaredField("hooks"); f.setAccessible(true); IdentityHashMap l = (IdentityHashMap) f.get(null); for (Iterator it = l.entrySet().iterator(); it.hasNext();) { Entry e = (Entry) it.next(); Thread o = (Thread) e.getKey(); if ((o != null) && (o.getClass().getClassLoader() != null) && (o.getClass().getClassLoader().getClass() == CClassLoader.class)) { it.remove(); continue; } o = (Thread) e.getValue(); if ((o != null) && (o.getClass().getClassLoader() != null) && (o.getClass().getClassLoader().getClass() == CClassLoader.class)) { it.remove(); } } } catch (Throwable ignore) { } try { if ((UIManager.getLookAndFeel() != null) && (UIManager.getLookAndFeel().getClass().getClassLoader() != null) && (UIManager.getLookAndFeel().getClass().getClassLoader().getClass() == CClassLoader.class)) { UIManager.setLookAndFeel((LookAndFeel) null); } Field f = UIManager.class.getDeclaredField("currentLAFState"); f.setAccessible(true); Object lafstate = f.get(null); if (lafstate != null) { Field fmultiUIDefaults = lafstate.getClass().getDeclaredField("multiUIDefaults"); fmultiUIDefaults.setAccessible(true); Object multiUIDefaults = fmultiUIDefaults.get(lafstate); Method clear = multiUIDefaults.getClass().getDeclaredMethod("clear", (Class[]) null); clear.setAccessible(true); clear.invoke(multiUIDefaults, (Object[]) null); Field tbl = lafstate.getClass().getDeclaredField("tables"); tbl.setAccessible(true); Hashtable[] tables = (Hashtable[]) tbl.get(lafstate); if (tables != null) { for (int i = 0; i < tables.length; i++) { Hashtable element = tables[i]; if (element != null) { element.clear(); } } } } } catch (Throwable ignore) { } try { Hashtable tb = UIManager.getDefaults(); Object cl = tb.get("ClassLoader"); if (cl.getClass() == CClassLoader.class) { tb.put("ClassLoader", CClassLoader.rootLoader.getParent()); } } catch (Throwable ignore) { } Method logFactoryRelease = null; try { logFactoryRelease = CClassLoader.rootLoader.loadClass("org.apache.commons.logging.LogFactory") .getMethod("release", new Class[] { ClassLoader.class }); } catch (final Throwable ignore) { } CClassLoader.rootLoader._destroy(logFactoryRelease); CClassLoader.mandatoryLoadersMap.clear(); CClassLoader.rootLoader = null; // deregister any sql driver loaded try { final List deregisterList = new ArrayList(); for (final Enumeration it = DriverManager.getDrivers(); it.hasMoreElements();) { final Driver d = (Driver) it.nextElement(); if ((d != null) && (d.getClass().getClassLoader() != null) && (d.getClass().getClassLoader().getClass() == CClassLoader.class)) { deregisterList.add(d); } } for (int i = 0; i < deregisterList.size(); i++) { final Driver driver = (Driver) deregisterList.get(i); DriverManager.deregisterDriver(driver); } } catch (final Throwable ignore) { } // stop dandling thread created with this classloader // tested only on sun jdk ThreadGroup tg = Thread.currentThread().getThreadGroup(); while ((tg != null) && (tg.getParent() != null)) { tg = tg.getParent(); } List ltg = new ArrayList(); ltg.add(tg); CClassLoader.getThreadGroups(tg, ltg); for (int ii = 0; ii < ltg.size(); ii++) { try { final ThreadGroup g = (ThreadGroup) ltg.get(ii); final Field fthreads = ThreadGroup.class.getDeclaredField("threads"); fthreads.setAccessible(true); final List toStop = new ArrayList(); Object threads[] = null; if (fthreads.getType() == Vector.class) { // in gnu classpath threads = ((Vector) fthreads.get(g)).toArray(); } else { // sun threads = (Object[]) fthreads.get(g); } for (int i = 0; i < threads.length; i++) { if (threads[i] == null) { continue; } if ((threads[i] != null) && (((Thread) threads[i]).getContextClassLoader() != null) && (((Thread) threads[i]).getContextClassLoader().getClass() == CClassLoader.class)) { ((Thread) threads[i]).setContextClassLoader(null); } if ((threads[i] != null) && (threads[i].getClass().getClassLoader() != null) && (threads[i].getClass().getClassLoader().getClass() == CClassLoader.class)) { toStop.add((Thread) threads[i]); } // remove any object in threadLocal referring an object // loaded // by this classloader tree try { final Field fthreadLocals = Thread.class.getDeclaredField("threadLocals"); fthreadLocals.setAccessible(true); final Object threadLocals = fthreadLocals.get(threads[i]); if (threadLocals != null) { final Field ftable = threadLocals.getClass().getDeclaredField("table"); ftable.setAccessible(true); final Object table[] = (Object[]) ftable.get(threadLocals); for (int kk = 0; kk < table.length; kk++) { final Object element = table[kk]; if (element != null) { final Field fvalue = element.getClass().getDeclaredField("value"); fvalue.setAccessible(true); final Object value = fvalue.get(element); if ((value != null) && (value.getClass().getClassLoader() != null) && (value .getClass().getClassLoader().getClass() == CClassLoader.class)) { fvalue.set(element, null); } if (value instanceof Map) { clearMap((Map) value); } else if (value instanceof List) { clearList((List) value); } else if (value instanceof Set) { clearSet((Set) value); } else if (value instanceof Object[]) { clearArray((Object[]) value); } fvalue.setAccessible(false); } } ftable.setAccessible(false); } fthreadLocals.setAccessible(false); } catch (final Throwable ignore) { ignore.printStackTrace(); } // remove any object in threadLocal referring an object // loaded // by this classloader tree try { final Field fthreadLocals = Thread.class.getDeclaredField("inheritableThreadLocals"); fthreadLocals.setAccessible(true); final Object threadLocals = fthreadLocals.get(threads[i]); if (threadLocals != null) { final Field ftable = threadLocals.getClass().getDeclaredField("table"); ftable.setAccessible(true); final Object table[] = (Object[]) ftable.get(threadLocals); for (int kk = 0; kk < table.length; kk++) { final Object element = table[kk]; if (element != null) { final Field fvalue = element.getClass().getDeclaredField("value"); fvalue.setAccessible(true); final Object value = fvalue.get(element); if ((value != null) && (value.getClass().getClassLoader() != null) && (value .getClass().getClassLoader().getClass() == CClassLoader.class)) { fvalue.set(element, null); } if (value instanceof Map) { clearMap((Map) value); } else if (value instanceof List) { clearList((List) value); } else if (value instanceof Set) { clearSet((Set) value); } else if (value instanceof Object[]) { clearArray((Object[]) value); } fvalue.setAccessible(false); } } ftable.setAccessible(false); } fthreadLocals.setAccessible(false); } catch (final Throwable ignore) { ignore.printStackTrace(); } // remove any protection domain referring this loader tree try { final Field finheritedAccessControlContext = Thread.class .getDeclaredField("inheritedAccessControlContext"); finheritedAccessControlContext.setAccessible(true); final Object inheritedAccessControlContext = finheritedAccessControlContext.get(threads[i]); if (inheritedAccessControlContext != null) { final Field fcontext = AccessControlContext.class.getDeclaredField("context"); fcontext.setAccessible(true); final Object context[] = (Object[]) fcontext.get(inheritedAccessControlContext); if (context != null) { for (int k = 0; k < context.length; k++) { if (context[k] == null) continue; final Field fclassloader = ProtectionDomain.class .getDeclaredField("classloader"); fclassloader.setAccessible(true); final Object classloader = fclassloader.get(context[k]); if ((classloader != null) && (classloader.getClass() == CClassLoader.class)) { context[k] = null; } fclassloader.setAccessible(false); } } fcontext.setAccessible(false); } finheritedAccessControlContext.setAccessible(false); } catch (final Throwable ignore) { ignore.printStackTrace(); } } fthreads.setAccessible(false); for (int i = 0; i < toStop.size(); i++) { try { final Thread t = (Thread) toStop.get(i); final Method stop = t.getClass().getMethod("stop", (Class[]) null); stop.invoke(t, (Object[]) null); } catch (final Throwable ignore) { } } } catch (final Throwable ignore) { } } try { CThreadContext.destroy(); } catch (Throwable ignore) { } System.runFinalization(); System.gc(); Introspector.flushCaches(); System.out.println("Destroying YAHP ClassLoader Tree : done"); }
From source file:org.apache.axis2.classloader.MultiParentClassLoader.java
public void destroy() { synchronized (this) { if (destroyed) { return; }// ww w . j a v a2s . c o m destroyed = true; } LogFactory.release(this); // clearSoftCache(ObjectInputStream.class, "subclassAudits"); // clearSoftCache(ObjectOutputStream.class, "subclassAudits"); // clearSoftCache(ObjectStreamClass.class, "localDescs"); // clearSoftCache(ObjectStreamClass.class, "reflectors"); // The beanInfoCache in java.beans.Introspector will hold on to Classes which // it has introspected. If we don't flush the cache, we may run out of // Permanent Generation space. Introspector.flushCaches(); }
From source file:org.deegree.enterprise.servlet.OGCServletController.java
@Override public void destroy() { super.destroy(); Enumeration<Driver> e = DriverManager.getDrivers(); while (e.hasMoreElements()) { Driver driver = e.nextElement(); try {//from w w w. j a v a 2 s .com if (driver.getClass().getClassLoader() == getClass().getClassLoader()) DriverManager.deregisterDriver(driver); } catch (SQLException e1) { LOG.logError("Cannot unload driver: " + driver); } } LogFactory.releaseAll(); LogManager.shutdown(); // SLF4JLogFactory.releaseAll(); // should be the same as the LogFactory.releaseAll call Iterator<Class<?>> i = IIORegistry.getDefaultInstance().getCategories(); while (i.hasNext()) { Class<?> c = i.next(); Iterator<?> k = IIORegistry.getDefaultInstance().getServiceProviders(c, false); while (k.hasNext()) { Object o = k.next(); if (o.getClass().getClassLoader() == getClass().getClassLoader()) { IIORegistry.getDefaultInstance().deregisterServiceProvider(o); LOG.logDebug("Deregistering JAI driver ", o.getClass()); } } } Introspector.flushCaches(); // just clear the configurations for now, it does not hurt CRSConfiguration.DEFINED_CONFIGURATIONS.clear(); }
From source file:org.deegree.services.controller.OGCFrontController.java
/** * Apply workarounds for classloader leaks, see eg. <a * href="http://java.jiderhamn.se/2012/02/26/classloader-leaks-v-common-mistakes-and-known-offenders/">this blog * post</a>.//from w ww. j a va 2 s.c om */ private void plugClassLoaderLeaks() { // if the feature store manager does this, it breaks try { ThreadedFeatureInputStream.shutdown(); } catch (Throwable e) { // just eat it } Executor.getInstance().shutdown(); LogFactory.releaseAll(); LogManager.shutdown(); // image io Iterator<Class<?>> i = IIORegistry.getDefaultInstance().getCategories(); while (i.hasNext()) { Class<?> c = i.next(); Iterator<?> k = IIORegistry.getDefaultInstance().getServiceProviders(c, false); while (k.hasNext()) { Object o = k.next(); if (o.getClass().getClassLoader() == getClass().getClassLoader()) { IIORegistry.getDefaultInstance().deregisterServiceProvider(o); LOG.debug("Deregistering " + o); k = IIORegistry.getDefaultInstance().getServiceProviders(c, false); } } } // JSF Introspector.flushCaches(); // Batik try { Class<?> cls = Class.forName("org.apache.batik.util.CleanerThread"); if (cls != null) { Field field = cls.getDeclaredField("thread"); field.setAccessible(true); Object obj = field.get(null); if (obj != null) { // interrupt is ignored by the thread ((Thread) obj).stop(); } } } catch (Exception ex) { LOG.warn("Problem when trying to fix batik class loader leak."); } }
From source file:org.eclipse.wb.internal.core.utils.reflect.ReflectionUtils.java
/** * @return the {@link BeanInfo} of given component {@link Class}. *///from w w w .j ava2 s .c o m public static BeanInfo getBeanInfo(Class<?> clazz) throws IntrospectionException { // standard components don't have BeanInfo's { String className = clazz.getName(); if (className.startsWith("java.lang.") || className.startsWith("java.awt.") || className.startsWith("javax.swing.") || className.startsWith("org.eclipse.swt") || className.startsWith("org.eclipse.jface") || className.startsWith("org.eclipse.ui.forms")) { return null; } } // OK, get BeanInfo (may be not trivial) Introspector.flushCaches(); String[] standard_beanInfoSearchPath = Introspector.getBeanInfoSearchPath(); try { Introspector.setBeanInfoSearchPath(new String[] {}); return Introspector.getBeanInfo(clazz); } finally { Introspector.flushCaches(); Introspector.setBeanInfoSearchPath(standard_beanInfoSearchPath); } }