Two questions concerning SUN applet classloader

Z

zorci

Hi,

I wonder why

a) applet classes are (sometimes) requested twice and
b) Component/JComponent classes are requested although never needed at
runtime.

Please take a look at the following simple SCE:

=== TestApplet.java ===
import java.awt.Applet;
public class TestApplet extends Applet {

TestObject o;
public void init() {
try {Class.forName("foo");}
catch (ClassNotFoundException e) {}
}
void neverCalled() {
add(o);
}
}

=== TestObject.java ===
import java.awt.Component;
public class TestObject extends Component {}

=== test.html ===
<html><body><applet code="TestApplet.class" width=100 height=100></
applet></body></html>

As you can see, TestObject never gets instanciated, and neverCalled()
is never called. The class.forName() is just for tracing the actions
in the access logfile. Putting each file into one web directory,
compiling and calling test.html results in my case (IE6 or Firefox,
SUN Java plugin 1.5.0_11 with disabled cache) in

.... "GET /web/test.html HTTP/1.1" 304 ...
.... "GET /web/TestApplet.class HTTP/1.1" 200 561 ...
.... "GET /web/TestObject.class HTTP/1.1" 200 200 ...
.... "GET /web/TestApplet.class HTTP/1.1" 200 561 ...
.... "GET /web/foo.class HTTP/1.1" 404 330 ...

In my opinion, requests three and four are _not_necessary_ and slow
down applet startup time. Switching to the JApplet/JComponent does not
make any difference.

Could anybody give me a hint why TestApplet.class is requested twice
and even TestObject.class is requested although not needed at runtime?

Any help is greatly appreciated.
 
A

Andrew Thompson

Hi,

I wonder why..

I've 'stopped' wonderring why any particular
applet caching (or otherwise) happens in any
particular browser/VM combo. It is simply
a) too upredictable.
b) completely out of the immediate control of a
(sandboxed) applet.
Could anybody give me a hint why TestApplet.class is requested twice

Sh*t happens? What browser (make, version and OS)
runnning what verison of Java (manufacturer, version
and OS) are you speaking of, hear?

Applet 'inconsistencies' between browser versions
and Java versions can pretty much be expected.
and even TestObject.class is requested although not needed at runtime?

Any help is greatly appreciated.

Have you looked into web start deployment*?

This deployment environment is much more stable
and predictable than your average browser/VM
combo.

* E.G.s <http://www.physci.org/jws/>
 
T

Thomas Fritsch

I wonder why

a) applet classes are (sometimes) requested twice and
I don't know, too.
b) Component/JComponent classes are requested although never needed at
runtime.
If you have an applet, Component *is* needed at runtime, because it is
an (indirect) superclass of Applet and JApplet:
Applet extends Panel extends Container extends Component.
JApplet extends Applet extends ... extends Component.
 
Z

zorci

Andrew, first thank you for your response.
Applet 'inconsistencies' between browser versions
and Java versions can pretty much be expected.

Sure, but please look at this example:

====== JavaApp.java ======
import java.awt.Panel;

public class TestApp {
TestObject o;
void neverCalled() {
Panel p=new Panel();
p.add(o);
}
public static void main(String args[]) {}
}

Compile it, delete TestObject.class, run TestApp and you'll get an
"NoClassDefFoundError: TestObject". As you can see here, at least the
problem of the unneeded class request (TestObject.class) is not applet-
related and occurs also in applications. Of course no one would
recognize a delay since all classes have been preloaded.
Have you looked into web start deployment*?

Not very deep... I'm still not sure if Java WebStart can be an
alternative to our html/applet-based website due to the following:

1. In contrast to applets, applications cannot play together with the
HTML framework. Much recoding would have to be done to put everything
into an java application.
2. In a HTML framework, Java applets can be substituted by alternative
non-java technologies like javascript or html. Applications cannot.
b) completely out of the immediate control of a
(sandboxed) applet.

A JarIndex gives you pretty much control over what code modules are
loaded by an applet at a specific time. Of course one need to be
careful to put the right classes into the right jar's. In WebStart
applications, all the code is loaded at startup by default, even if
unneeded. Applets can of course also be versionized, e.g. by using
different URLs or control the SUN cache state using cache* params.

WebStart is a very good thing when dealing with pure applications, but
in our case it does not seem to be a good alternative right now...
 
Z

zorci

I don't know, too.
mhmm...


If you have an applet, Component *is* needed at runtime, because it is
an (indirect) superclass of Applet and JApplet:
Applet extends Panel extends Container extends Component.
JApplet extends Applet extends ... extends Component.

Sure, Component.class is ok, but why has my TestObject.class been
requested?
 
Z

zorci

Sure, Component.class is ok, but why has my TestObject.class been
Because of the member variable
TestObject o;

in your code. You requested it.

No. As long as I just declare and not instanciate a member variable,
the SUN VM(1.4+) does NOT load the .class file since there is no need.
Try it by removing neverCalled() - no error occurs after deleting
TestObject.class. It has something to do with Component.add()...

Has anybody else an idea?
 
T

Tom Hawtin

No. As long as I just declare and not instanciate a member variable,
the SUN VM(1.4+) does NOT load the .class file since there is no need.
Try it by removing neverCalled() - no error occurs after deleting
TestObject.class. It has something to do with Component.add()...

The original code:

public class TestApplet extends Applet {

TestObject o;
....
add(o);

The TestApplet class needs to be verified before it can be initialised.
As part of the verification it needs to check that the call to
add(Ljava/awt/Component;)Ljava/awt/Component; is valid, i.e. is
TestObject as subtype of Component. In order to determine this, the
verifier is going to need to load TestObject.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top