classloader

Running an uber jar from sbt assembly results in error: Could not find or load main class

為{幸葍}努か 提交于 2019-12-03 17:03:22
问题 I have a spark job packaged as an uber-jar using the sbt assembly plugin. The build.sbt specifies a runnable main to be the target of the resulting uber-jar mainClass in assembly := Some("com.foo.Bar") After the assembly is correctly created, running the intended command: java -jar assembly.jar results in Error: Could not find or load main class com.foo.Bar Using the an alternative method, like java -cp assembly.jar com.foo.Bar gives the same error message. Then, I extracted the contents of

Finding running instances in a running JVM

人盡茶涼 提交于 2019-12-03 16:42:50
I'm wondering if it's possible to get a handle on running instances of a given class. The particular issue that triggered this was an application that doesn't exit nicely because of a number of running threads. Yes, I know you can daemonize the theads, and they won't then hold up the application exit. But it did get me to wondering if this was possible. The closest thing I can is the classloaders (protected!) findLoadedClass , although you'd have to run through your own classloader to do this. On a related note, is this how profiling tools manage to track object handles? by running through

How Classloader determines which classes it can load?

那年仲夏 提交于 2019-12-03 16:31:53
I'm reading on class loading in Java. Motivation Assuming we have a classloader hierarchy that looks like this, I understand that classes loaded by First are not directly accessible by classes loaded by Second (and vice versa). Bootstrap | System | Common / \ First Second I also understand that a classloader checks with its parent class loader whether it can load the class and, if that is the case, delegates the loading to its parent. Question How do classloaders actually determine whether they can load some given class? That differs depending on the implementation of the classloader. But all

ThreadLocal garbage collection

二次信任 提交于 2019-12-03 15:56:04
问题 From javadoc Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its copies of thread-local instances are subject to garbage collection (unless other references to these copies exist). from that it seems that objects referenced by a ThreadLocal variable are garbage collected only when thread dies. But what if ThreadLocal variable a is no more referenced and is

Looking for basic example of using Apache Felix in dynamic loading of Jar file and instancing a class at runtime in Java

丶灬走出姿态 提交于 2019-12-03 15:34:21
I tried implementing my own class loader based on some examples. However, I think it is not working as expected ( unable to reload Jar file etc. I see few references of recommending using OSGI or Apache Felix for handling Jar file loading. Is there any examples of loading Jar, instancing a class from the Jar? More details on what I am trying to accomplish..I have a Java command line application that essentially continuously runs. I want it to be able to reference JAR files dynamically at runtime and at run-time instance a class in these jars. These jars may contain 1 or more supporting classes

Resources and config loading in maven project

霸气de小男生 提交于 2019-12-03 15:20:55
I'm using Maven for desktop applycation. I read about Maven standart directory layout and I have this project structure for now: App |-- pom.xml `-- src |-- main |-- java | `-- java classes |-- resources | `-- images | `-- app images `--config `--config.xml I want to find a way to load my resources and config files. I read some articles and topics and found this (simplified example from my code): //class for loading config public class Preferences { public Preferences() { InputStream image = Preferences.class.getResourceAsStream("images/image.png"); InputStream config = Preferences.class

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

两盒软妹~` 提交于 2019-12-03 15:14:11
问题 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

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

谁说我不能喝 提交于 2019-12-03 14:37:55
问题 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)

How to diagnose a Java 8 metaspace leak?

和自甴很熟 提交于 2019-12-03 14:29:01
问题 I have a J2EE application with some interesting behavior ... the heap seems to behave well, growing and shrinking with garbage collections as expected over time. There is no appreciable overall long term heap expansion. However, the metaspace just keeps steadily growing at about 20 Mb per hour until we hit MaxMetaspace and encounter an OOME. I have tried both the parallel and G1 garbage collectors (jdk1.8.0_40). The application is not getting re-deployed during the execution, so it doesn't

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

天涯浪子 提交于 2019-12-03 14:19:36
问题 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