classloader

ClassLoader Leak - Are they worth solving?

我的未来我决定 提交于 2019-12-03 05:45:57
ClassLoader leaks usually result in java.lang.OutOfMemoryError: PermGen . In the instance of working on application servers you may see this as a result of many redeploys of a common application. The explanation and possible resolutions to this problem can be seen on these two links. (among others) http://dev.eclipse.org/blogs/memoryanalyzer/2008/05/17/the-unknown-generation-perm/ http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java Now for the most part they are easy to get around. Simply increase the -XX:MaxPermSize and when the inevitable happens, restart the JVM

Want to run non-threadsafe library in parallel - can it be done using multiple classloaders?

主宰稳场 提交于 2019-12-03 05:23:32
I work on a project where we use a library that is not guaranteed thread-safe (and isn't) and single-threaded in a Java 8 streams scenario, which works as expected. We would like to use parallel streams to get the low hanging scalability fruit. Unfortunately this cause the library to fail - most likely because one instance interferes with variables shared with the other instance - hence we need isolation. I was considering using a separate classloader for each instance (possibly thread local) which to my knowledge should mean that for all practical purposes that I get the isolation needed but

What does “new” do in Java w.r.t. class loader?

非 Y 不嫁゛ 提交于 2019-12-03 04:52:47
I cannot easily find it in JLS/JVMSpec, nor in SO. I'm sure it must've been asked... So, what does "new" do actually? Suppose we instantiate a class B in A: class A { // ... new B(); // ... } Is this equivalent to class A { // ... A.class.getClassLoader().loadClass("B's canonical name").newInstance(); // ... } ? Does it, or does it not work like that in every environment? I'd be grateful if you can point me to the appropriate chapter in JLS/JVMSpec. Thanks! Edit: surely we can't call B.class.getCanonicalName() in loadClass() call, since B's not loaded yet. JVM has to resolve the name based on

this.getClass().getResource(“”).getPath() returns an incorrect path

岁酱吖の 提交于 2019-12-03 03:32:49
I am currently making a small simple Java program for my Computer Science Final, which needs to get the path of the current running class. The class files are in the C:\2013\game\ folder. To get this path, I call this code segment in my main class constructor: public game(){ String testPath = this.getClass().getResource("").getPath(); //Rest of game } However, this command instead returns this String: "/" despite the correct output being "C:/2013/game" Additionally, I attempted to rectify this by using this code: public game(){ String testPath = this.getClass().getClassLoader().getResource("")

Error while instrumenting class files (asm.ClassWriter.getCommonSuperClass)

╄→гoц情女王★ 提交于 2019-12-03 03:31:48
Getting error on instrumentation java.lang.RuntimeException: java.lang.ClassNotFoundException: Deposit at org.objectweb.asm.ClassWriter.getCommonSuperClass(Unknown Source) at org.objectweb.asm.ClassWriter.a(Unknown Source) at org.objectweb.asm.Frame.a(Unknown Source) at org.objectweb.asm.Frame.a(Unknown Source) at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source) at com.jConSequence.instrumentor.methodProber.AdddataBaseDetailsInstructions$AdddataBaseDetailsMethodInstructions.visitMaxs(AdddataBaseDetailsInstructions.java:131) at org.objectweb.asm.ClassReader.accept(Unknown Source) at org

PermGen space issue with Glassfish/Hibernate

大兔子大兔子 提交于 2019-12-03 03:26:48
I'm running a GWT+Hibernate app on Glassfish 3.1. After a few hours, I run out of Permgen space. This is without any webapp reloads. I'm running with –XX:MaxPermSize=256m –XmX1024m . I took the advice from this page , and found that I'm leaking tons of classes- all of my Hibernate models and all of my GWT RequestFactory proxies. The guide referenced above says to "inspect the chains, locate the accidental reference, and fix the code". Easier said than done. The classloader always points back to an instance of org.glassfish.web.loader.WebappClassLoader . Digging further, I find lots of

How JVM starts looking for classes?

人盡茶涼 提交于 2019-12-02 22:31:08
I was curious about what all locations JVM looks for executing a program? I'm more interested in understanding in what sequence and where does JVM look for class files, like does it look into java libs, extension libs, classpath any directory like the current directory from where the java is invoked? I'm more interested in JVM behaviour and not how class loader load class, which I know has parent delegation mechanism till root. If a class is executed from directory where the compiled class is kept on file system and also in a jar file in the same directory, would JVM load both or just one and

loading BufferedImage with ClassLoader.getResource()

主宰稳场 提交于 2019-12-02 22:29:42
问题 I am trying to load an image file (gif) which is stored locally in the same directory as my Eclipse java project: ref is the relative path where the gif image is stored. public Sprite getSprite(String ref) { BufferedImage sourceImage = null; try { URL url = this.getClass().getClassLoader().getResource(ref); if (url == null) { fail("Can't find ref: "+ref); } sourceImage = ImageIO.read(url); } catch (IOException e) { fail("Failed to load: "+ref); } } The client code that uses the above method

What happens when java program starts?

不想你离开。 提交于 2019-12-02 21:12:55
Recently have been touched Java classloaders and suddenly recognized that do not fully understand what happens step-by-step when someone calls java -jar App.jar Well I guess a new instance of JVM is created it uses ClassLoader to load main class and other classes byte-code is started to execute from main() method But still I suppose there are many things I need to know more about it. Who and how decides which classes should be loaded at startup and which once needed? I have found two related questions but there it is not explained how to apply that to Java realities. What happens when a

How to determine absolute path (if any) of a loaded Class?

走远了吗. 提交于 2019-12-02 21:02:45
Is there a (compatible, if possible) way to determine the absolute path of a loaded Class? Of course, this is not always possible (if you think of dynamically created classes), but if the loaded Class is inside a jar how to get the absolute path for this jar? MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath() Fullcode: package org.life.java.so.questions; /** * * @author jigar */ public class GetClassPath { public static void main(String[] args) { System.out.println(GetClassPath.class.getProtectionDomain().getCodeSource().getLocation().getPath()); } } Output: /C: