No.
Object o = ctx.lookup( "my_home_interface" );
my.home.interface mhi = (my.home.interface)o;
When I said RMI classloading, I am talking about what happens in
MarshalledObject.get(). When RMI goes to deserialize an object, it needs to
load the class, and it uses ContextClassLoader for that. Which means that
the instance of the class that you get returned to you is loaded by the
right class loader.
In this code there are 2 (or 3) classloading operations going on. When you
call ctx.lookup, your class is being loaded by RMI, probably using the
context classloader, in an explicit CL.loadClass() call. When you use a
class name as a symbol in your code (in a variable declaration, in a cast,
in a .Class operation) an implicit classload is performed by the JVM,
because that symbol is translated by the jvm into a class object. The
implicit classload uses the defining classloader of the class that the JVM
is currently executing. So would a Class.forName.
In other words, the JVM NEVER uses ContextClassLoader for default
classloading. It is only used when explicit call is made to
Thread.currentThread().getContextClassLoader().loadClass(x). However, some
standard classes, like java.rmi.MarshalledObject, use it in that way, so it
can be useful under certain circumstances. It is also a convenient way to
keep track of a classloader that you want all your classes to use without
passing it through every method call - Jboss uses it that way fairly often.
-----Original Message-----
From: Tom Cook [mailto:[EMAIL PROTECTED]]
Sent: Sunday, February 18, 2001 10:51 PM
To: JBoss-User
Subject: RE: [jBoss-User] DYNAMIC CLASSLOADING
On Mon, 19 Feb 2001, you wrote:
[snip]
> On Fri, 16 Feb 2001, you wrote:
> > This, however, seems to obviate the purpose of the setContextClassLoader
> > method. What exactly is it good for?
[snip]
> No. Used only for dynamic classloading.
>
> I believe it is used as the default class loader for RMI, as well as by
> DataTransfer.
>
Ah, so something like this could work:
URL urls[] = ...;
ClassLoader cl = new URLClassLoader( urls );
Thread.currentThread().setContextClassLoader( cl );
System.setSecurityManager( new RMISecurityManager() );
InitialContext ctx = new InitialContext();
Object o = ctx.lookup( "my_home_interface" );
my.home.interface mhi = (my.home.interface)o;
And then it would use RMI classloading to download the classes from the
server,
yes?
Or does RMI class loading work differently again?
Tom
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]