Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Loading a class using the applet class loader

Reply
Thread Tools

Loading a class using the applet class loader

 
 
=?iso-8859-1?q?Andr=E9_Wagner?=
Guest
Posts: n/a
 
      05-30-2007
Hello,

I'm loading classes during the execution of a applet, like this:

ClassLoader cl = getClass().getClassLoader();
Class c = cl.loadClass(className);
MyObject o = (MyObject)c.newInstance();

It works fine, but if the class is big, the applet execution hangs
until the whole class is downloaded from the server and loaded. Is
there any way I can download the class (showing the user a progressbar
for that) and load the bytecode? I tried using the defineClass method,
but I can't overwrite in the applet class loader it because of the
applet security restrictions.

Thank you in advance,

André

 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      05-30-2007
André Wagner wrote On 05/30/07 14:04,:
> Hello,
>
> I'm loading classes during the execution of a applet, like this:
>
> ClassLoader cl = getClass().getClassLoader();
> Class c = cl.loadClass(className);
> MyObject o = (MyObject)c.newInstance();
>
> It works fine, but if the class is big, the applet execution hangs
> until the whole class is downloaded from the server and loaded. Is
> there any way I can download the class (showing the user a progressbar
> for that) and load the bytecode? I tried using the defineClass method,
> but I can't overwrite in the applet class loader it because of the
> applet security restrictions.


Perhaps an expert will think of something, but I
doubt what you ask for is possible. However, could
you run a separate Thread to load the class while the
rest of your applet keeps on executing?

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
=?iso-8859-1?q?Andr=E9_Wagner?=
Guest
Posts: n/a
 
      05-30-2007
> Perhaps an expert will think of something, but I
> doubt what you ask for is possible.


I see...

> However, could
> you run a separate Thread to load the class while the
> rest of your applet keeps on executing?


Well, while this is not what I had in mind, it certainly is better
than hanging the applet. Thank you for the hint.

André

 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      05-30-2007
André Wagner wrote:
> Hello,
>
> I'm loading classes during the execution of a applet, like this:
>
> ClassLoader cl = getClass().getClassLoader();
> Class c = cl.loadClass(className);
> MyObject o = (MyObject)c.newInstance();
>
> It works fine, but if the class is big, the applet execution hangs
> until the whole class is downloaded from the server and loaded. Is
> there any way I can download the class (showing the user a progressbar
> for that) and load the bytecode? I tried using the defineClass method,
> but I can't overwrite in the applet class loader it because of the
> applet security restrictions.


I don't see why not, but I'm not an expert, so take this with a grain of
salt.

Subclass an appropriate classloader so you have your own classloader to
play with. Probably, you will need to subclass URLClassLoader.
Override the findClass() method to check the size of any class it finds,
and throw up a progress bar if the size is over X, where X is some
number of bytes that you think will take "too long" to download. Then
use your new classloader to load the rest of the app (you'll need a
small stub at the beginning of the app to start things off).

Alternate, make your own classloader and override it's findClass()
method. Make a second class that just does a regular old HTTP or FTP
download of a lot of different stuff: several classes and resources. In
other words, this second class downloads everything in one go. Your own
classloader in this case will know about this second class and look
there for any files first, before handing them off to the default
classloader. This way, you can download everything in one shot, and
have it available so the user doesn't have to wait.

Just a couple of ideas. I've never tried this, so good luck.
 
Reply With Quote
 
=?iso-8859-1?q?Andr=E9_Wagner?=
Guest
Posts: n/a
 
      05-31-2007
> Just a couple of ideas. I've never tried this, so good luck.

Thank you for the hints, but unfortunately, this is impossible. An
applet has a series of security restrictions, and one of these
restrictions is that a applet can never subclass or create a class
loader.

André

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      05-31-2007
André Wagner wrote:
..
>I'm loading classes during the execution of a applet, ...


Why?
...
>It works fine, but if the class is big, the applet execution hangs
>until the whole class is downloaded from the server and loaded. Is
>there any way I can download the class (showing the user a progressbar
>for that) and load the bytecode?


It might be possible to offer this information if the applet
is launched using web start, the classes added to the
classpath and specified as a 'lazy' download.

Here is my latest best effort to achieve the lazy
downloads with a progress dialog.
<http://www.physci.org/jws/cache/#latesteg>
This example deals with images as the resources,
but the API is more intended for classes.

I experienced some problems with the progress
dialog offered, that I have not had time to resolve.
Maybe you can track down solutions.

HTH

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.asp...neral/200705/1

 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      05-31-2007
André Wagner wrote:

> Thank you for the hints, but unfortunately, this is impossible. An
> applet has a series of security restrictions, and one of these
> restrictions is that a applet can never subclass or create a class
> loader.


Huh, this is new to me. Where did you hear this at? My brief search
didn't find anything that hinted at this...
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      05-31-2007
Mark Space wrote:

> Huh, this is new to me. Where did you hear this at? My brief search
> didn't find anything that hinted at this...


nm, found one. Applet classloaders can easily be sub-classed, but the
browser running it won't let you (normally). Sorry about that.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Class Loader for Web Application using Tomcat tapas.adhikary Software 0 04-22-2008 08:53 AM
Library class loader (setting system class loader parent) Karsten Wutzke Java 0 06-29-2007 04:44 AM
display a message that Applet is loading! while applet loads shaillenkumar@gmail.com Javascript 1 06-09-2006 08:24 AM
Applet Loader Wayne Gibson Java 3 01-10-2006 05:19 PM
Java Applet loading in Applet Viewer but not in HTML page Archana Java 1 10-24-2004 11:41 PM



Advertisments