Classloader purpose

What exactly is the purpose of a classloader and how exactly does it work.

What exactly is the purpose of a classloader and how
exactly does it work.jverd has pointed out some good links but just in case
you want a summary, Lets start from the building
blocks. The smallest unit of execution that gets
loaded by a ClassLoader is the Java class file. A
class file contains the binary representation of a
Java class, which has the executable bytecodes and
references to other classes used by that class,
including references to classes in the Java API.
Stated simply, a ClassLoader locates the bytecodes for
a Java class that needs to be loaded, reads the
bytecodes, and creates an instance of the
java.lang.Class class. This makes the class available
to the JVM for execution. Initially when a JVM starts
up, nothing is loaded into it. The class file of the
program being executed is loaded first and then other
classes and interfaces are loaded as they get
referenced in the bytecode being executed. The JVM
thus exhibits lazy loading, i.e., loading classes only
when required, so at start-up the JVM doesn't need to
know the classes that would get loaded during runtime.
Multiple instances of ClassLoaders exist in the Java 2
runtime, each loading classes from different code
repositories. For instance, Java core API classes are
loaded by the bootstrap (or primordial) ClassLoader.
Application-specific classes are loaded by the system
(or application) ClassLoader. In addition, an
application can define its own ClassLoaders to load
code from custom repositories e.g the web server
classloaders. Java 2 defines a parent-child
relationship between ClassLoaders. Each ClassLoader
except the bootstrap ClassLoader has a parent
ClassLoader, conceptually forming a treelike structure
of ClassLoaders. The bootstrap ClassLoader is the root
of this tree and thus doesn't have a parent.
HTH
♠Thats a good description. I was however more interested in how it works? I mean what are the steps that take place for it to get active?????? I am not sure if I am phrasing my question right.

Similar Messages

  • ClassNotFoundException in EJB's and Threads (Classloader issue)

    A very interesting bug has cropped up in WebLogic 6.1. When a J2EE
    application packaged appropriately, a client application running in a
    user-created Thread will always throw a ClassNotFoundException when
    attempting to get back a user-created object from an EJB living on
    another cluster. This error does not happen when the call is being made
    from outside a Thread.
    Sounds strange, I know, so I'll try to give everyone as much detail as
    possible so they can avoid this bug, and so that the folks at BEA can
    fix it.
    * A java class running inside a clustered WL6.1 server is attempting to
    reference an EJB on another clustered WL 6.1 server. Accessing the bean
    is not a problem, the client class is able to obtain a remote reference
    to the bean and make method calls on it. Calling a method causes the
    following stack trace:
    2002-01-11 10:36:57,331 [Thread-4] ERROR
    wpni.app.mywp.display.DisplayJobs$JobsMonitor -
    wpni.app.mywp.display.DisplayJobs$JobsMonitor.run: Error checking Jobs
    status.
    java.rmi.UnmarshalException: failed to unmarshal class
    wpni.app.jobs.JobsData; nested exception is:
    java.lang.ClassNotFoundException: wpni.app.jobs.JobsData: This
    error could indicate that a component was deployed on a cluster member
    but not other members of that cluster. Make sure that any component
    deployed on a server that is part of a cluster is also deployed on all
    other members of that cluster
    java.lang.ClassNotFoundException: wpni.app.jobs.JobsData: This error
    could indicate that a component was deployed on a cluster member but
    not other members of that cluster. Make sure that any component deployed
    on a server that is part of a cluster is also deployed on all other
    members of that cluster
    at
    weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:146)
    at
    weblogic.rjvm.MsgAbbrevInputStream.readClassDescriptor(MsgAbbrevInputStream.java:211)
    at
    weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.readClassDescriptor(ChunkedObjectInputStream.java:290)
    at
    java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:906)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
    at
    java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
    at
    weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:107)
    at
    weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:115)
    at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:56)
    at
    weblogic.rmi.internal.BasicRemoteRef.unmarshalReturn(BasicRemoteRef.java:230)
    at
    weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:254)
    at
    weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:220)
    at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
    at $Proxy140.getJobsData(Unknown Source)
    at
    wpni.app.mywp.display.DisplayJobs$JobsMonitor.run(DisplayJobs.java:48)
    at java.lang.Thread.run(Thread.java:484)
    * The class that is not found (JobsData) is definitely in the EAR file
    on both the client cluster and the server cluster, and in the
    appropriate location.
    * When we attempted to run the code outside of a Thread, everything
    worked perfectly, so it was definitely the Thread that was causing the
    problem.
    * Deploying the EJB on the client cluster did not do anything to solve
    the problem.
    * Adding the JobsData to the System CLASSPATH at the startup of the
    WebLogic server DID solve the problem. But of course that defeats the
    purpose of packaging everything in the EAR file.
    So, the conclusion seems to be that when DisplayJobs$JobsMonitor kicked
    off the Thread, the Thread should have been created in either the WAR's
    classloader or the JAR's classloader (wouldn't matter, since the
    JobsData class is in the JAR's classloader, which is a parent of the
    WAR's classloader). But instead, the Thread is being created in the
    System classloader, which can't find the JobsData class!
    We believe that any Thread created by a class living within an EAR's
    classloader should remain within that same classloader, and not migrate
    to any other classloader, in order to avoid situations like this. We're
    opening a case with BEA to attempt to get this resolved. In the
    meantime, we recommend to developers that if they have to make
    cross-cluster RMI calls from inside user-created Threads, that they only
    attempt to receive primitive types or standard JDK objects. Otherwise,
    you'll have to add the classes to the System CLASSPATH at startup of the
    WebLogic instance.
    Thanks,
    Erin
    * "[White House spokeperson Ari] Fleischer
    * warned Democrats this morning against
    * investigations into the Bush administration's
    * dealings with Enron. 'The American people
    * are tired of partisan witch hunts and endless
    * investigations,' he said." [Ed.: Uh... ]
    * www.washingtonpost.com/wp-dyn/articles/A25159-2002Jan10.html
    * Erin Reid Myers, Chief Architect
    * WashingtonPost.Newsweek Interactive
    * [email protected]
    * Work: (703) 469-3154
    * Cell: (703) 725-3050
    [att1.html]

    Things can go seriously wrong if your application uses user threads (violating
    EJB spec programming restrictions and BEA recommendations).
    I'm curious, does it work if you enable network classloading on the server
    which invokes remote EJB (in config.xml -
    <Server NetworkClassLoadingEnabled="true" ...
    </Server>
    Erin Reid Myers <[email protected]> wrote:
    A very interesting bug has cropped up in WebLogic 6.1. When a J2EE
    application packaged appropriately, a client application running in a
    user-created Thread will always throw a ClassNotFoundException when
    attempting to get back a user-created object from an EJB living on
    another cluster. This error does not happen when the call is being made
    from outside a Thread.
    Sounds strange, I know, so I'll try to give everyone as much detail as
    possible so they can avoid this bug, and so that the folks at BEA can
    fix it.
    * A java class running inside a clustered WL6.1 server is attempting to
    reference an EJB on another clustered WL 6.1 server. Accessing the bean
    is not a problem, the client class is able to obtain a remote reference
    to the bean and make method calls on it. Calling a method causes the
    following stack trace:
    2002-01-11 10:36:57,331 [Thread-4] ERROR
    wpni.app.mywp.display.DisplayJobs$JobsMonitor -
    wpni.app.mywp.display.DisplayJobs$JobsMonitor.run: Error checking Jobs
    status.
    java.rmi.UnmarshalException: failed to unmarshal class
    wpni.app.jobs.JobsData; nested exception is:
    java.lang.ClassNotFoundException: wpni.app.jobs.JobsData: This
    error could indicate that a component was deployed on a cluster member
    but not other members of that cluster. Make sure that any component
    deployed on a server that is part of a cluster is also deployed on all
    other members of that cluster
    java.lang.ClassNotFoundException: wpni.app.jobs.JobsData: This error
    could indicate that a component was deployed on a cluster member but
    not other members of that cluster. Make sure that any component deployed
    on a server that is part of a cluster is also deployed on all other
    members of that cluster
    at
    weblogic.j2ee.ApplicationManager.loadClass(ApplicationManager.java:146)
    at
    weblogic.rjvm.MsgAbbrevInputStream.readClassDescriptor(MsgAbbrevInputStream.java:211)
    at
    weblogic.common.internal.ChunkedObjectInputStream$NestedObjectInputStream.readClassDescriptor(ChunkedObjectInputStream.java:290)
    at
    java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:906)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:366)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
    at
    java.io.ObjectInputStream.inputObject(ObjectInputStream.java:1186)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:386)
    at
    java.io.ObjectInputStream.readObject(ObjectInputStream.java:236)
    at
    weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:107)
    at
    weblogic.common.internal.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:115)
    at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:56)
    at
    weblogic.rmi.internal.BasicRemoteRef.unmarshalReturn(BasicRemoteRef.java:230)
    at
    weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:254)
    at
    weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:220)
    at weblogic.rmi.internal.ProxyStub.invoke(ProxyStub.java:35)
    at $Proxy140.getJobsData(Unknown Source)
    at
    wpni.app.mywp.display.DisplayJobs$JobsMonitor.run(DisplayJobs.java:48)
    at java.lang.Thread.run(Thread.java:484)
    * The class that is not found (JobsData) is definitely in the EAR file
    on both the client cluster and the server cluster, and in the
    appropriate location.
    * When we attempted to run the code outside of a Thread, everything
    worked perfectly, so it was definitely the Thread that was causing the
    problem.
    * Deploying the EJB on the client cluster did not do anything to solve
    the problem.
    * Adding the JobsData to the System CLASSPATH at the startup of the
    WebLogic server DID solve the problem. But of course that defeats the
    purpose of packaging everything in the EAR file.
    So, the conclusion seems to be that when DisplayJobs$JobsMonitor kicked
    off the Thread, the Thread should have been created in either the WAR's
    classloader or the JAR's classloader (wouldn't matter, since the
    JobsData class is in the JAR's classloader, which is a parent of the
    WAR's classloader). But instead, the Thread is being created in the
    System classloader, which can't find the JobsData class!
    We believe that any Thread created by a class living within an EAR's
    classloader should remain within that same classloader, and not migrate
    to any other classloader, in order to avoid situations like this. We're
    opening a case with BEA to attempt to get this resolved. In the
    meantime, we recommend to developers that if they have to make
    cross-cluster RMI calls from inside user-created Threads, that they only
    attempt to receive primitive types or standard JDK objects. Otherwise,
    you'll have to add the classes to the System CLASSPATH at startup of the
    WebLogic instance.
    Thanks,
    Erin
    * "[White House spokeperson Ari] Fleischer
    * warned Democrats this morning against
    * investigations into the Bush administration's
    * dealings with Enron. 'The American people
    * are tired of partisan witch hunts and endless
    * investigations,' he said." [Ed.: Uh... ]
    * www.washingtonpost.com/wp-dyn/articles/A25159-2002Jan10.html
    * Erin Reid Myers, Chief Architect
    * WashingtonPost.Newsweek Interactive
    * [email protected]
    * Work: (703) 469-3154
    * Cell: (703) 725-3050
    Dimitri

  • How does ClassLoader work?

    I have to use ClassLoader.getSystemResource() in my tool.
    this tool shall be portable to different OS.
    when I use the tool on my NT4 it works properly, but running it on W2k it crashes.....
    what is the difference between the usage under NT and W2k ???
    why does one (in the same structure) work, the other not?
    can anybody explain how this "getSystemResource" generally works?
    thX a lot!

    From the blue book:
    getResourceAsStream()
    PURPOSE: Finds and creates an input stream on a resource associated with the class represented by this
    Class object.
    Try a small test program on both OS's to see if this is truly the cause of the crash.
    package com.bar.foo;
    import java.io.*;
    import java.util.*;
    public class Foo extends Object {
        public static void main(String [] args) {
            getProps("/com/bar/foo/foo.cfg");
        public static void getProps(String propsFile) {
            String prop = null;
            try {
                InputStream in = Foo.class.getResourceAsStream(propsFile);
                if(in == null) System.out.println("Ooops! No properties read.");
                Properties props = new Properties();
                props.load(in);
                if(props.getProperty("foo") != "") prop = props.getProperty("foo");
                props.list(System.out);
                in.close();
            } catch (Exception ex) { }
    The config file looks like this:
    roy% cat com/bar/foo/foo.cfg
    foo=bar
    Compile and run like so:
    roy% javac -d . Foo.java
    roy% jar cvf foo.jar com
    added manifest
    adding: com/(in = 0) (out= 0)(stored 0%)
    adding: com/bar/(in = 0) (out= 0)(stored 0%)
    adding: com/bar/foo/(in = 0) (out= 0)(stored 0%)
    adding: com/bar/foo/Foo.class(in = 1420) (out= 805)(deflated 43%)
    adding: com/bar/foo/foo.cfg(in = 8) (out= 10)(deflated -25%)
    roy% java -classpath foo.jar com.bar.foo.Foo
    -- listing properties --
    foo=bar

  • Classloader problem with exploded EAR

    I'm trying to un-jar an EAR file and then un-jar the EJB jars within EAR and putting
    all the EJB and other classes from those jar files in the main application directory
    like application/com/abc/***. I have few WARs within EAR but I'm trying not to
    explode (un-jar) those. One of the WAR file has a JSP page and a depentent java
    class within it but when I try to use that JSP, I'm getting "java.lang.NoClassDefFoundError"
    exception. Any ideas?
    Is there a better/standard way to explode an EAR for development purposes?

    I had similar problem today with an EAR application using EclipseLink 1.0.1 on WebLogic Server 10.3.
    The stack trace looks a little different,
    java.lang.NoClassDefFoundError: org/eclipse/persistence/internal/jpa/deployment/DirectoryArchive$1
    at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.init(DirectoryArchive.java:89)
    at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.<init>(DirectoryArchive.java:73)
    at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.<init>(DirectoryArchive.java:55)
    at org.eclipse.persistence.internal.jpa.deployment.ArchiveFactoryImpl.createArchive(ArchiveFactoryImpl.java:75)
    at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:184)
    at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.initialize(JPAInitializer.java:132)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:104)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:64)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
    but the cause is the same: instances of JPA provider were cached in javax.persistence.Persistence which is loaded in WLS system classloader.
    When EAR is redeployed, the EclipseLink jar located in the EAR is reloaded but the cached instance is not updated.
    The reflection workaround did work but there is even simpler workaround: just copy eclipselink.jar (or other JPA provider JARs) into the
    /lib directory of the WLS domain -- the JARs in lib folders are loaded before EAR and would not be redeployed every time.

  • EJBs accessing protected classes from java classloader

    Hello,
    We are facing a problem with classes isolation. I read from this newsgroup that
    to access a package level class from the base classloader from a bean, the supporting
    classes has to be from the same classloader as the bean. Well I think the only
    way we could do that is to have the *Bean.class in the base classloader, which
    is not what's recommended or move the support classes into the bean's classloader,
    which we cannot do.
    The purpose of this mail is to ask: is it a bug from weblogic server? Will it
    be fixed one day? If not, does it mean that it is impossible to isolate classes
    for local access from public classes?
    Thank you, Khiet.

    Thank you for your reply.
    Hope that one day we will not be obliged to have anything in the main classpath.
    :) Khiet.
    Rob Woollen <[email protected]> wrote:
    Tran T. Khiet wrote:
    Hello,
    We are facing a problem with classes isolation. I read from this newsgroupthat
    to access a package level class from the base classloader from a bean,the supporting
    classes has to be from the same classloader as the bean. Well I thinkthe only
    way we could do that is to have the *Bean.class in the base classloader,which
    is not what's recommended or move the support classes into the bean'sclassloader,
    which we cannot do.All correct.
    The purpose of this mail is to ask: is it a bug from weblogic server?No, it's how java classloaders work.
    Will it
    be fixed one day? If not, does it mean that it is impossible to isolateclasses
    for local access from public classes?You can expect that future versions of WLS will allow the user more
    control over classloaders, but for now you'll need public or protected
    access to cross classloaders.
    -- Rob
    Thank you, Khiet.

  • AuditProvider classloading issues

    Hi all,
    We are implementing an AuditProvider for WLS that communicates via SOAP with a custom application that provides secure audit storage.
    We have followed the following example to implement the base of the provider:
    https://codesamples.projects.dev2dev.bea.com/servlets/Scarab?id=S189
    After that, we used the clientgen Ant task to generate the SOAP access code, and packaged everything in an MJF file using MBeanMaker.
    We copy the MJF to WL_HOME/server/lib/mbeantypes, configure the MBean using the admin console.
    However, when restarting stuff, during our AuditProvider initialization we get:
    javax.xml.rpc.ServiceException: weblogic client internal deployment descriptor com/kroopier/bea/sap/soap/BEAAuditLogService_internaldd.xml not found. Please make sure all clientgen generated files are in the classpath.
            at weblogic.wsee.jaxrpc.ServiceImpl.loadWeblogicDD(ServiceImpl.java:397)
            at weblogic.wsee.jaxrpc.ServiceImpl.loadInternalDD(ServiceImpl.java:346)
            at weblogic.wsee.jaxrpc.ServiceImpl.<init>(ServiceImpl.java:110)
            at com.kroopier.bea.sap.soap.BEAAuditLogService_Impl.<init>(BEAAuditLogService_Impl.java:21)
            at com.kroopier.bea.sap.soap.BEAAuditLogService_Impl.<init>(BEAAuditLogService_Impl.java:17)
            Truncated. see log file for complete stacktraceUpon further research, it seems that the SOAP code generated by clientGen uses Thread.currentThread().getContextClassLoader() to load the support files (some xml files it generates). We suspect that this class loader is not the class loader being used to load the mjf jar, so the mjf jar contents (which include the file that cannot be found) are not used.
    Is there a simple way to solve this?
    Kind regards,
    Alex

    Thank you.
    As we are creating an AuditProvider for distribution, we'd rather have it be a single jar file that goes into mbeantypes than having to put our jar into system classpath (i.e. I'd think this would make our provider less desirable).
    My current line of reasoning is as follows:
    1. We are trying to invoke code from our AuditProvider that uses Thread.currentThread().getContextClassLoader() for reflection purposes
    2. Thread.currentThread().getContextClassLoader() does not include the AuditProvider jar deployed in mbeantypes, but the one in this.getClass().getClassLoader() does (I suspect that the this.getClass().getClassLoader() is the one that the class uses for loading the classes it needs).
    3. Why would someone use Thread.currentThread().getContextClassLoader() to load classes? Clearly, if you are loading the rest of the classes your class needs with this.getClass().getClassLoader(), use that one, as you don't know what your thread's context class loader is.
    Therefore, our hacky solution is to do this:
    ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
      // bad code that uses the thread's context class loader
    finally {
      Thread.currentThread().setContextClassLoader(threadClassLoader);
    }Long term, I'd like to advise people (esp. the guys who wrote weblogic.wsee.tools.anttasks.ClientGenTask and Hessian- which is the code that's given us trouble so far) to use the current class' classloader for reflection stuff instead of the thread's.
    Of course, I have my doubts that this hack won't cause further trouble, so I'd appreciate further feedback on this issue.
    Alex

  • Hot Deployment & ClassLoader Re-Use

    I've implemented a service that observes changes to a jar file's timestamp, and utilizes a new UrlClassLoader to hot deploy class changes. It's working well in isolation, but I wonder how it will perform in production. The work is based on the October 31, 2000 JDC Tech Tips ( http://java.sun.com/developer/TechTips/2000/tt1027.html ).
    I've tried to improve on the example code and I wonder if my change will help or haunt me. The example creates a new URLClassLoader every time the class is requested by name. In comparison, I wanted to only create a new class loader when necessary. To do so, I collect the class loader used for a given class name and re-use it on the next request if the underlying jar file has not changed. Is this a wise approach? Anything else I should be thinking about?
    Here's some sample code to illustrate:
        protected HashMap jarMap = null;
        protected HashSet classesUpgraded = null;
        protected HashMap classLoaders = null;
        protected IUpgradeObserver observer = null;
        public Class getClass(String xtlClassName) throws ClassNotFoundException {
            Class c = null;
            File f = getJar(xtlClassName);
            observer.notifyIfChanged(f);
            try {
                if(f != null) {
                    lazyInitClassesUpgraded();
                    if(classesUpgraded.contains(xtlClassName)) {
                        // the jar has changed, so create a new class loader
                        Dbug.print(dbugTag, "Reloading " + xtlClassName + " from jar with timestamp " + f.lastModified());
                        ClassLoader loader = new URLClassLoader(new URL[]{f.toURL()});
                        c = loader.loadClass(xtlClassName);
                        if (c != null) {
                            classesUpgraded.remove(xtlClassName);
                            lazyInitClassLoaders();
                            classLoaders.put(xtlClassName, loader);
                    } else {
                        // the class has already been loaded from the current jar - reuse the existing class loader
                        lazyInitClassLoaders();
                        ClassLoader loader = (ClassLoader)classLoaders.get(xtlClassName);
                        c = loader.loadClass(xtlClassName);
            } catch (MalformedURLException urle) {
                urle.printStackTrace();
            if(c == null) {
                throw new ClassNotFoundException("The Xtencil jars did not contain " + xtlClassName);
            } else {
                return c;
        }

    legosa - Sure, some portion of getClass must be synchronized to reduce the likelihood of an additional new class def being created when two threads enter getClass at the same time. The other points you make are good as well, and I initially became aware of them in reading the Sun example. As far as I can tell, they shouldn't affect us. I'm not writing a general-purpose class loader. My work is only used to load a specific type of "map" that is frequently updated. We always go through the same factory function to create these maps by name. No singletons will be generated through the utility, and it should be fine for two class objects to exist for a given class name. Basically, the software looks up a map implementation by name, runs it, marks the map as garbage, and moves on to the next. If I plug my class loader into our other web-based container, I have more concerns, since many users may be requesting maps and the old class definitions are less likely to be garbage at any given time.
    pekoe - Thanks for the heads up on HotSwap. Unfortunately, as I understand it, the work is intended for development environments, not production servers. For example, it requires the JVM be in debug mode!

  • Why classloader doesnot have abstract methods

    Hi
    I am looking at ClassLoader source code from src.zip under jdk1.5
    I see the ClassLoader class definition as abstract but none of the methods are declared as abstract. Why findClass is not an abstract method?
    Am I looking at something wrong?
    Or
    Is this designed purposefully ?
    Thanks in advance
    -Tumu

    Why findClass is not an abstract method?Because it has a default implementation, as defined by ClassLoader.
    Am I looking at something wrong?No.
    Is this designed purposefully ?Yes. Classes may be declared abstract that have no abstract methods. This is perfectly legal.

  • Classloader order issue

    Hi!
    Actually I need to load a jar file before any other file on my WAR file.
    I've a cluster of two managed servers in different machines.
    Which is the best way to do it and where to put the jar file in both machines?
    Thanks a lot
    A.

    Depends on where your jars are located. If you insert them in the system (or server) classloader they will be loaded once,
    by the system classloader. You can use the ${DOMAIN_HOME}/lib directory for this purpose. The jars located in this directory will be
    picked up and added to the end of the server classpath at server startup. The jars will be ordered lexically in the classpath.
    If you want to use the system classloader to add your jars, you can also edit the commEnv script (located in the <middleware-home>/wlserver_10.3/common/bin directory).
    Find the WEBLOGIC_CLASSPATH entry and add your jars to classpath.
    Another point to note is that the manifest class-path header is the only packaging method to allow control over the precedence of classes.
    Order is not defined for the WEB-INF/lib loader.
    To use the manifest loader, add a META-INF/MANIFEST.MF to your exploded directory and add the following class-path header: Class-Path: <directory>/some.jar <directory>/other.jar.

  • Classloader + Namespace troubles

    Hi I have the following problem regarding classloaders:
    Here are my class/program structure:
    Root Dir:
    MyLoader.java
    InterfaceA.java
    Sub Dir:
    ImplA.java --> extends InterfaceA
    B.java --> ImplA & B are in same package and hence able to call each others protected methods.
    MyLoader loads 'ImplA.java' and calls a public method against 'InterfaceA.java' (note 'MyLoader' has no visibility to 'ImplA' directly, only 'InterfaceA'). The public method in 'InterfaceA' calls a protected method on 'ImplA' which calls a protected method on 'B'.
    When I run ImplA directly, it's able to call the protected method in B.
    When I load 'ImplA' and call the method against 'InterfaceA', I get the following error:
    java.lang.IllegalAccessError: tried to access method SubDir.B.shutdown()V from class SubDir.ImplA.
    I understand the error as follows:
    Since the method is originally called on 'InterfaceA' by 'MyLoader', 'InterfaceA' has no access to call the protected method against 'B' (even though it says ImplA in the error).
    The catch is, if I make 'ImplA' visibile to classloader that loads 'MyLoader', then it defeats the purpose of writing a custom classloader.
    Hence how would I get around this error without making the shutdown() method public (a dangerous method).
    Thanks & regards

    B should be loaded by MyLoader since this is the default behaviour: when a new class is required that has not been loaded yet, it is loaded by the referencing classloader (refer to "RELATING CLASS LOADERS TO THE CLASS PATH" in the following article: http://developer.java.sun.com/developer/TechTips/2000/tt1027.html#tip1)
    Regards

  • Classloading Order in /WEB-INF/lib

    hi all,
    we are using wl 8.1sp2 and we have a problem with the classloading in a webapp. The requested class is loaded on startup.
    My question is: In which ordering are the classes - or better jar-files - loaded, which are located in the /WEB-INF/lib directory... is it alpha-numerical? random?
    Is there a way to control the ordering?
    I browsed the tutorials but could not find an answer to that question.
    - odilo

    I am running into exactly the same issue. I haven't found any solution yet.
    Our primary reason for having the same classes in multiple jars is for patch release purposes. We would like to drop a patch jar into a directory (ideally somewhere other than WEB-INF/lib) and prepend it to the classpath via some mechanism... for example the Class-Path attr of MANIFEST.MF
    One alternative is to replace the entire existing core jar file with a patched version. This is quite inconvenient with our current QA process, since the complete functionality would have to be re-tested rather than just a point test of the patched area.
    I could also envision a need for this in a situation where you have third-party libraries. It's not always easy to control their packaging. Sometimes they come bundled with old utility classes which you would like to shadow with newer versions.

  • JRE classloading issue

    Hi,
    I have an application where I use JAF(Java Activation Framework) source code for my purpose. My application works fine with jdk1.5. When I run my application with jdk1.6, it does not work properly.
    The cause is JAF is included in JRE1.6 and my application refers to the JAF present in the JRE not the one in my application.
    My question is by any means can I ignore the JAF present in JRE1.6 and use the one present with my application?
    Any help is appriciated.
    Champak

    cutecolt wrote:
    I need to deploy a java application in a unix box.Deploy?
    Do you just mean "run" or "launch" - or do you mean deploy under an AppServer framework?
    when i wanted to execute the same application in the unix box, I get NoClassDefFound for the library jars though i have set the classpath and the write permissions are there for the lib jar files.NoClassDefFound for the library jars?
    Do you mean you get NoClassDefFound for the class containing "main()" or some other specific class?
    You don't get NoClassDefFound for jars...
    But i found the issue may be in the JRE conflict. I have 2 jre's available in the box. You can have several JREs installed. That does not cause conflicts.
    When i type java -version, it is showing, 1.4.2_08 but my application was compatible with jdk 1.5 and infact 1.5.0 is also available in the machine.This just means that your 1.4.2 JRE is on your PATH and is the first place the shell found "java".
    I tried to exectue the program by changing to the jdk 1.5.0 path like /app/instals/jdk1/5/bin/java -cp /lib/hibernate.jar abc. so i didn't get the unsupportedversionexception.You mean by launching java using the fully qualified name.
    But none of the jars in the classpath wasn't loaded. Huh?
    I think there is some classloading issue associated with JRE. Unlikely.
    How i use the 1.5.0 jre? Same way as the 1.4.2 JRE.
    Btw, there are some application running in the box so i may not be able to switch to 1.5 entirely.Not relevant.

  • How to recover from an exception on a class loaded with a classloader?

    I have created a classloader for the purpose of dynamically loading "modules" . The whole application is multithreaded and the separate modules may also run as separate threads. The problem that I am facing is that if one of the modules crashes (does not handle an exception), then the class loader object which loaded the required classes and started the module's thread, cannot be accessed. The thread which attempts to access this class loader freezes. Is there any way to recover from this situation?
    Thanks in advance

    Ok, let me provide a bit more information. Each "module" is handled by specific class (let's call it ModuleDescriptor), which subclasses the URLClassLoader class. The ModuleDescriptor class is responsible for describing each module, maintain module state information (loaded, unloaded, started, stopped, etc) and also executing some method calls on a specific object of the module, which in essence acts as a means to start or stop the module. Each module is a separate thread and is packaged in a JAR file, which is first downloaded locally. If one of these module threads crashes, then I cannot even call a method of the ModuleDescriptor to perform the necessary unloading bit. Basically, when I can the method that thread of execution halts without an exception or an error or anything. The rest of the application continues working properly (other threads). I find this situation bizarre, because the ModuleDescriptor object and the actual module with the thread that crashed execute on separate threads. If there is any more specific information that I have to provide, please let me know.

  • Gather statistics about classloader

    I can gather statistics like
    1.No of classes loaded.
    2.Memory used by the JVM.
    3.Threads created about the JVM (default ClassLoader of the JVM).
    I need to do the same for any generic ClassLoader.
    The code I use to gather information for the JVM's ClassLoader is as follows:
    import java.io.IOException;
    import java.lang.management.ClassLoadingMXBean;
    import java.lang.management.ManagementFactory;
    import java.lang.management.OperatingSystemMXBean;
    import java.net.MalformedURLException;
    import javax.management.MBeanServer;
    import javax.management.MBeanServerConnection;
    import javax.management.remote.JMXConnector;
    import javax.management.remote.JMXConnectorFactory;
    import javax.management.remote.JMXConnectorServer;
    import javax.management.remote.JMXConnectorServerFactory;
    import javax.management.remote.JMXServiceURL;
    public class ClassLoading {
    public static void main(String args[]) throws MalformedURLException, IOException
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
    JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    cs.start();
    JMXServiceURL url1 = cs.getAddress();
    JMXConnector jmxc = JMXConnectorFactory.connect(url1, null);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    final ClassLoadingMXBean clmb = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.CLASS_LOADING_MXBEAN_NAME, ClassLoadingMXBean.class);
    System.out.println("Loaded class count"+clmb.getLoadedClassCount());
    final OperatingSystemMXBean osmxb = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
    System.out.println("Name"+osmxb.getName());
    }

    Hi Nicolas. You're right that we recommend using DBMS_STATS for most statistics-gathering purposes. I'll pass this along to the writer who manages the Database Reference, to see that it gets updated. I'll also ask him to check the clarity of the column descriptions.
    Regards,
    Diana

  • Using multiple apple id's for different purposes

    We are a family of 4 with numerous devices. Here's the setup we've been using to manage different aspects of our apple life!
    Each of us has an individual apple id, which we use on our individual devices for storage/backup, photo stream, facetime, calendar etc
    We have one apple id, used on all devices for all app store/itunes purchases
    We entered this id on each device with everything turned off except "find my iphone". This way we could be logged into the find my iphone app with one id and be able to see all our devices.
    This has worked really well for us as a family. Well, yesterday my kids updated their phones (one 5 and one 4s) to ios 7. I have not done it yet. It does not seem to allow for the above setup, specifically where "find my iphone" is concerned. When I enter in that specific apple id as an additional icloud account, it doesn't offer the option of find my iphone. My ios 6 device says "only your main account can use photo stream, documents & data, and backup". Their device adds "find my iphone" to this list.
    Does anyone know if this is a specific change apple made, or something that went wrong when initially setting up their updated phones.
    TIA!

    Thanks for your reply. But what I don't understand is, can I no longer have multiple icloud accounts, to be used for different purposes? Like I said, we have been using one apple id/icloud for storage etc and one for find my iphone.

Maybe you are looking for

  • After upgrading to Mavericks I cannot update iPhoto and iMovie. Why?

    Just got my first Mac, an iMac. I upgraded to Maverick and once done I find there are updates available for iPhoto and iMovie. First I have tried to register "accept" the two apps. Nothing happens. Then I try to update them and get the answer that th

  • Photoshop keeps crashing error 150:30 please help

    I have photoshop CS4 and CS5 that I got through doing an associates degree program. They've worked fine in the past, but recently they've started giving me a message when I try to use them that the licensing has stopped working and the error is 150:3

  • Role of nscd in 5.1 directory server

    Hi, Can somebody tell me the role of nscd in iplanet 5.1 directory server? I assume this has to be disabled on directory server for better performance by adding enable-cache hosts no in /etc/nscd.conf file. Can somebody validate this?? If possible wi

  • How to load Transaction Data from BW to BPC

    Hi, Can you please provide me step by step description forTransaction data load from BW infocube to BPC Application? Is there any PDF for the same? Regards, Ram Edited by: Ramchandra Laxmikant Puranik on May 18, 2011 3:23 PM Edited by: Ramchandra Lax

  • Outlook 2007

    After doing a google search on this issue and seeing only hints that Oracle may or may not have said that a connector compatible with Outlook 2007 may be coming in the spring of 2008 or maybe Jan 2008 or maybe summer 2008, I have seen nothing from Or