contextclassloader

How can I safely solve this Java context classloader problem?

亡梦爱人 提交于 2020-01-12 05:22:10
问题 One and only one of my hundreds of users has trouble starting my Java desktop app. It only starts for him about one-third of the time. The other two-thirds of the time a NullPointerException is thrown at startup: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:394) at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.java:1327) at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.java:1309) at

Cannot add web application to built-in Tomcat of @SpringBootApplication with main-thread's context class loader

自作多情 提交于 2020-01-07 02:29:27
问题 I am trying to load a war as web application that I ship with my standalone jar . As my @SpringBootApplication is starting up, I extract the war file and copy it to the file system. After that I make a simple tomcat.addWebapp() call which I'd expect to work. But take a look: @Bean public EmbeddedServletContainerFactory servletContainerFactory() { return new TomcatEmbeddedServletContainerFactory() { @Override protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat

Why Does Clojure Use the Context Classloader by Default?

时光总嘲笑我的痴心妄想 提交于 2019-12-18 12:53:03
问题 Why is use-context-classloader set to true by default? Why doesn't Clojure use the current class loader? 回答1: you can override its behavior by setting clojure.lang.Compiler.LOADER to the class loader ie. final ClassLoader ccl= ClojurePlugin.class.getClassLoader(); clojure.lang.Var.pushThreadBindings(clojure.lang.RT.map( clojure.lang.Compiler.LOADER, ccl) ); try { ... clojure.lang.RT.loadResourceScript( cljFile ); ... }finally{ clojure.lang.RT.popThreadBindings(); } where ClojurePlugin is your

Reload class file in tomcat

好久不见. 提交于 2019-12-08 06:11:11
问题 I am creating a class file at run time. I want to replace the existing class file with the updated one in the class loader. It is similar to hot swapping (e.g. JRebel) which avoids server restart and redeployment. I found context.xml approach for tomcat for context reloading. But it is not very useful in case of production environment. Can we register class with ClassLoader at runtime? Please suggest if any alternative is there to reload class at runtime. I am using following code to retrieve

Parallel stream doesn't set Thread.contextClassLoader after tomcat upgrade

不问归期 提交于 2019-12-07 03:59:25
问题 After tomcat upgrade from 8.5.6 to 8.5.28 parallel stream stopped supplying Threads with contextClassLoader: Because of it Warmer::run can't load classes in it. warmers.parallelStream().forEach(Warmer::run); Do you have any ideas what Tomcat was supplying for contextClassLoaders for new Threads? ParallelStream uses ForkJoinPool in newest Tomcat. 回答1: Common ForkJoin pool is problematic and could be responsible for memory leaks and for applications being able to load classes and resources from

Thread.getContextClassLoader() == null?

若如初见. 提交于 2019-12-07 02:48:49
问题 Can Thread.getContextClassLoader() be null ? The javadoc is not really clear. Should a library take this case into account ? Update: the reason I asked is that beansbinding.dev.java.net does not work in this case (and my code does setContextClassLoader(null) 回答1: Java threads created from JNI code in a non-java thread have null ContextClassloader unless the creator explicitly sets it. Also in such context Thread.currentThread() returns null. 回答2: Yes you should, someone could have called

Parallel stream doesn't set Thread.contextClassLoader after tomcat upgrade

假装没事ソ 提交于 2019-12-05 07:16:01
After tomcat upgrade from 8.5.6 to 8.5.28 parallel stream stopped supplying Threads with contextClassLoader: Because of it Warmer::run can't load classes in it. warmers.parallelStream().forEach(Warmer::run); Do you have any ideas what Tomcat was supplying for contextClassLoaders for new Threads? ParallelStream uses ForkJoinPool in newest Tomcat. Common ForkJoin pool is problematic and could be responsible for memory leaks and for applications being able to load classes and resources from other contexts/applications (potential security leak if your tomcat is multi tenant). See this Tomcat

How can I safely solve this Java context classloader problem?

南楼画角 提交于 2019-12-03 07:22:56
One and only one of my hundreds of users has trouble starting my Java desktop app. It only starts for him about one-third of the time. The other two-thirds of the time a NullPointerException is thrown at startup: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.util.Hashtable.put(Hashtable.java:394) at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.java:1327) at javax.swing.JEditorPane.registerEditorKitForContentType(JEditorPane.java:1309) at javax.swing.JEditorPane.loadDefaultKitsIfNecessary(JEditorPane.java:1387) at javax.swing.JEditorPane

Why Does Clojure Use the Context Classloader by Default?

旧时模样 提交于 2019-11-30 11:13:34
Why is use-context-classloader set to true by default? Why doesn't Clojure use the current class loader? you can override its behavior by setting clojure.lang.Compiler.LOADER to the class loader ie. final ClassLoader ccl= ClojurePlugin.class.getClassLoader(); clojure.lang.Var.pushThreadBindings(clojure.lang.RT.map( clojure.lang.Compiler.LOADER, ccl) ); try { ... clojure.lang.RT.loadResourceScript( cljFile ); ... }finally{ clojure.lang.RT.popThreadBindings(); } where ClojurePlugin is your class. but when you're using RT class the first time ever(ie. when RT class is loaded) it will use context

Java的classloader

懵懂的女人 提交于 2019-11-28 10:24:06
类加载器的基本概念 类加载器(class loader)用来加载 Java 类到 Java 虚拟机中。一般来说,Java 虚拟机使用 Java 类的方式如下:Java 源程序(.java 文件)在经过 Java 编译器编译之后就被转换成 Java 字节代码(.class 文件)。类加载器负责读取 Java 字节代码,并转换成 java.lang.Class类的一个实例。每个这样的实例用来表示一个 Java 类。通过此实例的 newInstance()方法就可以创建出该类的一个对象。 基本上所有的类加载器都是 java.lang.ClassLoader类的一个实例。 下面详细介绍这个 Java 类。 java.lang.ClassLoader类的基本职责就是根据一个指定的类的名称,找到或者生成其对应的字节代码,然后从这些字节代码中定义出一个 Java 类,即 java.lang.Class类的一个实例。除此之外,ClassLoader还负责加载 Java 应用所需的资源,如图像文件和配置文件等。为了完成加载类的这个职责,ClassLoader提供了一系列的方法,比较重要的方法如 表 1所示。关于这些方法的细节会在下面进行介绍。 表 1. ClassLoader 中与加载类相关的方法 方法 说明 getParent() 返回该类加载器的父类加载器。 loadClass(String