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 / GUI / October 2007

Tip: Looking for answers? Try searching our database.

Applets and custom class loaders

Thread view: 
Qu0ll - 16 Oct 2007 04:38 GMT
Is there any reason to use a custom class loader with an applet?  I have an
applet in which I only want to load a particular class if the corresponding
content type is required to be rendered by that applet so that the initial
applet load is as quick as possible.  I have considered using a custom class
loader whereby the applet would start a new thread in the init() method
which invokes this loader to download a XYZContentRenderer class in the
background for example.  But then I thought that I still need to cast the
resulting class to XYZContentRenderer so that reference to
XYZContentRenderer in the casting would already cause this class to be
loaded when the applet is loaded.

So therefore I see no benefit from using a custom class loader with an
applet.  Is this correct?  Is there any other way I can achieve what I am
trying to do here?

Signature

And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Andrew Thompson - 16 Oct 2007 05:45 GMT
>...  I have an
>applet in which I only want to load a particular class if the corresponding
>content type is required to be rendered by that applet so that the initial
>applet load is as quick as possible.  
...
>...Is there any other way I can achieve what I am
>trying to do here?

Web start, lazy downloads.
<http://www.physci.org/jws/#ds>

Signature

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

Qu0ll - 16 Oct 2007 07:55 GMT
>>...  I have an
>>applet in which I only want to load a particular class if the
[quoted text clipped - 7 lines]
> Web start, lazy downloads.
> <http://www.physci.org/jws/#ds>

JWS is not an option - I need something that runs *in* a browser.

Signature

And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

a24900@googlemail.com - 16 Oct 2007 07:05 GMT
> Is there any reason to use a custom class loader with an applet?  I have an
> applet in which I only want to load a particular class if the corresponding
> content type is required to be rendered by that applet so that the initial
> applet load is as quick as possible.

You don't need an additional class loader. Do not put the particular
class file in a Jar. Just put the class file on the server in the
right directory according to the package name. The applet will try to
load the class first time it is referenced. Since it is not in the Jar
(which has already been sent over the net) the class loader needs to
issues a new HTTP request first time the class is needed.

Of course you have to make absolutely sure the class is not referenced
before you use it. Consider programming against an interface and use
Class.forName() to load an interface implementation (your class) to
make sure you have better control over the class usage.

Then additional HTTP requests bear a certain overhead and delay and
therefore the whole idea of delayed loading a class might not be worse
it.
Qu0ll - 16 Oct 2007 07:56 GMT
> You don't need an additional class loader. Do not put the particular
> class file in a Jar. Just put the class file on the server in the
[quoted text clipped - 11 lines]
> therefore the whole idea of delayed loading a class might not be worse
> it.

Thanks, I like the idea of programming against an interface and then loading
the implementation indirectly.  I'll give it a go.

Signature

And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Qu0ll - 16 Oct 2007 08:02 GMT
>> Of course you have to make absolutely sure the class is not referenced
>> before you use it. Consider programming against an interface and use
>> Class.forName() to load an interface implementation (your class) to
>> make sure you have better control over the class usage.

Actually, is Class.forName() going to work in an unsigned applet?

Signature

And loving it,

-Q
_________________________________________________
Qu0llSixFour@gmail.com
(Replace the "SixFour" with numbers to email me)

Andrew Thompson - 16 Oct 2007 08:52 GMT
>>> Of course you have to make absolutely sure the class is not referenced
>>> before you use it. Consider programming against an interface and use
>>> Class.forName() to load an interface implementation (your class) to
>>> make sure you have better control over the class usage.
>
>Actually, is Class.forName() going to work in an unsigned applet?

Yes it should, so long as the classes are coming from the
same host as the applet.  In addition to loading loose classes
lazily, you *might* (if it makes sense) also load resources from
Jar files lazily.  Do not add them to the archives attribute
(obviously) and simply form a complete URL to the jar/resource
when accessing it.

Signature

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

a24900@googlemail.com - 16 Oct 2007 22:23 GMT
> In addition to loading loose classes
> lazily, you *might* (if it makes sense) also load resources from
> Jar files lazily.  Do not add them to the archives attribute
> (obviously) and simply form a complete URL to the jar/resource
> when accessing it.

The jar is sent as a whole over the network. A web server does not
understand a URL pointing into a jar, can not extract the class or
resource out of a jar and can not individually send a class or
resource from a jar. The class loader uses a URL pointing to the whole
jar to load the whole jar if needed. Once the jar has been loaded the
class loader extracts the particular resource from it.

If you want to load individual classes or resources do not put them in
a jar.
Andrew Thompson - 17 Oct 2007 00:50 GMT
On Oct 17, 7:23 am, "a24...@googlemail.com" <a24...@googlemail.com>
wrote:

> > In addition to loading loose classes
> > lazily, you *might* (if it makes sense) also load resources from
[quoted text clipped - 6 lines]
> resource out of a jar and can not individually send a class or
> resource from a jar.   ...

Which is not a problem, if it is 'one resource per jar'.

The OP mentioned lazy loading, which implies either
a lot of, or large, resources.  If the latter, the
Jar might make sense - or at least, Jar(s) for the
largest resource(s).

Andrew T.


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



©2008 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.