Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Two questions concerning SUN applet classloader

Thread view: 
zorci@epost.de - 27 Jul 2007 15:11 GMT
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.
Andrew Thompson - 27 Jul 2007 16:10 GMT
On Jul 28, 12:11 am, zo...@epost.de wrote:
> 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/>
zorci@epost.de - 27 Jul 2007 18:42 GMT
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...
Thomas Fritsch - 27 Jul 2007 16:42 GMT
> 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.

Signature

Thomas

zorci@epost.de - 27 Jul 2007 18:46 GMT
On 27 Jul., 17:42, Thomas Fritsch <i.dont.like.s...@invalid.com>
wrote:
> zo...@epost.de wrote:
> > I wonder why
>
> > a) applet classes are (sometimes) requested twice and
>
> I don't know, too.

mhmm...

> > b) Component/JComponent classes are requested although never needed at
> > runtime.
[quoted text clipped - 3 lines]
>    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?
Lew - 27 Jul 2007 20:44 GMT
> On 27 Jul., 17:42, Thomas Fritsch <i.dont.like.s...@invalid.com>
> wrote:
[quoted text clipped - 14 lines]
> Sure, Component.class is ok, but why has my TestObject.class been
> requested?

Because of the member variable
>   TestObject o;
in your code.  You requested it.

Signature

Lew

zorci@epost.de - 27 Jul 2007 21:50 GMT
> > Sure, Component.class is ok, but why has my TestObject.class been
> > requested?
[quoted text clipped - 3 lines]
>
> 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?
Tom Hawtin - 02 Aug 2007 17:49 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.