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 / January 2006

Tip: Looking for answers? Try searching our database.

Class.forName reasonably efficient

Thread view: 
Roedy Green - 14 Jan 2006 22:54 GMT
I did some timing of class.forName.  It turns out it is reasonably
quick

Class.forName eagerly loads the class if it not already loaded. Inside
the JVM there is a HashMap of all the classes that have been
previously loaded. So Class. forName takes under a millisecond if the
class you have want is already loaded, If not, it might take 15
milliseconds or so to load it. You pay this time penalty only the
first time you use the class. Class. forName is still slower than hard
coding the name of the class into your code. With hard coding, you
avoid repeated HashMap lookups.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

mgungora - 14 Jan 2006 23:10 GMT
Does Class.forName re-load a class if the timestamp on it is newer?
Probably not... Is there a way to force it to do a re-load?
Roedy Green - 14 Jan 2006 23:41 GMT
>Does Class.forName re-load a class if the timestamp on it is newer?
>Probably not... Is there a way to force it to do a re-load?

nope. It won't even look. Once you load a class it stays loaded. the
only way to do that is with a ClassLoader. Then to the jvm the new
class is a brand new class.

At some point I should write a demo to replace a class on the fly and
upgrade old to new objects.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

opalpa@gmail.com opalinski from opalpaweb - 15 Jan 2006 03:19 GMT
In most applications Roedy is completely correct --  a custom class
loader needs be created.  The exception I know of is that some servlet
servers have reloading as a configuration option.  One example is
com.iplanet.ias.classloader.IasWebClassLoader

Opalinski
opalpa@gmail.com
http://www.geocities.com/opalpaweb/
Dave Glasser - 15 Jan 2006 04:53 GMT
"opalpa@gmail.com opalinski from opalpaweb" <opalpa@gmail.com> wrote
on 14 Jan 2006 19:19:04 -0800 in comp.lang.java.programmer:

>In most applications Roedy is completely correct --  a custom class
>loader needs be created.  The exception I know of is that some servlet
>servers have reloading as a configuration option.  One example is
>com.iplanet.ias.classloader.IasWebClassLoader

And it would use a custom classloader. Or more specifically, one other
than the system classloader.

Signature

Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net



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.