Re: [OT] Deleting URLClassloader Cached Jars/Classes

2012-04-03 Thread Peter Lavin

Thanks guys, I'll look at this again, esp the JasperLoader,

thanks,
Peter

On 04/02/2012 11:20 PM, Pid wrote:

On 02/04/2012 22:33, Konstantin Kolinko wrote:

2012/4/3 Christopher Schultzch...@christopherschultz.net:



Is there a way to empty this cache, or disable caching all
together?


Not without implementing your own ClassLoader. You could read the code
for WebappClassLoader to see how it's done in there.



+1. You need your own class loader.


You would need your own *quite sophisticated* classloader.

This kind of thing is usually achieved with Java Agents that can rewrite
bytecode on the fly, like JavaRebel for example.


p


I would say org.apache.jasper.servlet.JasperLoader.  It is classloader
that is used to load JSP pages.  If the page is updated you just throw
classloader instance away together with the classes that it loaded.

In recent JVMs there is also an option to reload a class in memory
(aka hot-swap). That is used by debuggers, when you debug your program
in an IDE and want to continue with updated (edited) version of the
class without restarting all over.

It is not something that you would use from inside the JVM though.

Best regards,
Konstantin Kolinko

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org






--
with best regards,
Peter Lavin,
PhD Candidate,
Computer Architecture  Grid Research Group,
Lloyd Institute, 005,
Trinity College Dublin, Ireland.
+353 1 8961536

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Deleting URLClassloader Cached Jars/Classes

2012-04-02 Thread Peter Lavin


Hi all,
this may be a general Java question or their may be a specific answer 
related to Tomcat.


I am running a simple webservice which loads classes using a 
URLClassloader...


// start of code snippet
ClassLoader previous = Thread.currentThread()
.getContextClassLoader();
URLClassLoader loader = new URLClassLoader(new URL[]
 { new URL(http://localhost/classes/;)}, previous);


String className = common.MyClassToBeLoaded;
Class? ho = loader.loadClass(className);
// end

This ok, but when I edit and recompile a class which is loaded, the 
changes to MyClassToBeLoaded.java are not reflected in the webservice.


I suspect that the class is being cached and won't be cleared until the 
JVM restarts (i.e. the Tomcat server will have to be restarted).



My Question:
Is there a way to empty this cache, or disable caching all together?

There are some suggestions out there but none specific to Tomcat.

Effectively, I need to clear the cache, all the better if my code can do 
it each time I load the MyClassToBeLoaded.class.



Peter


--
with best regards,
Peter Lavin,
PhD Candidate,
Computer Architecture  Grid Research Group,
Lloyd Institute, 005,
Trinity College Dublin, Ireland.
+353 1 8961536

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: [OT] Deleting URLClassloader Cached Jars/Classes

2012-04-02 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Peter,

On 4/2/12 2:05 PM, Peter Lavin wrote:
 this may be a general Java question or their may be a specific
 answer related to Tomcat.

This is unrelated to Tomcat, since you are using java.net.URLClassLoader.

 I am running a simple webservice which loads classes using a 
 URLClassloader...
 
 // start of code snippet ClassLoader previous =
 Thread.currentThread() .getContextClassLoader(); URLClassLoader
 loader = new URLClassLoader(new URL[] { new
 URL(http://localhost/classes/;)}, previous);
 
 
 String className = common.MyClassToBeLoaded; Class? ho =
 loader.loadClass(className); // end
 
 This ok, but when I edit and recompile a class which is loaded,
 the changes to MyClassToBeLoaded.java are not reflected in the
 webservice.

That's the way most ClassLoaders work: they are designed to cache
classes so that performance doesn't totally suck. Imagine if the JVM
kept having to check to see if java.lang.Object had been updated...

 Is there a way to empty this cache, or disable caching all
 together?

Not without implementing your own ClassLoader. You could read the code
for WebappClassLoader to see how it's done in there.

 There are some suggestions out there but none specific to Tomcat.

That's because this can be done without regard to Tomcat's operation.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk96DrEACgkQ9CaO5/Lv0PBqMQCeLuGqS/3EF3475s7mavDRK/BQ
D9oAnAyjAtQYj89s6TM+iDPSIbVk0euN
=+2b2
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: [OT] Deleting URLClassloader Cached Jars/Classes

2012-04-02 Thread Konstantin Kolinko
2012/4/3 Christopher Schultz ch...@christopherschultz.net:

 Is there a way to empty this cache, or disable caching all
 together?

 Not without implementing your own ClassLoader. You could read the code
 for WebappClassLoader to see how it's done in there.


+1. You need your own class loader.

I would say org.apache.jasper.servlet.JasperLoader.  It is classloader
that is used to load JSP pages.  If the page is updated you just throw
classloader instance away together with the classes that it loaded.



In recent JVMs there is also an option to reload a class in memory
(aka hot-swap). That is used by debuggers, when you debug your program
in an IDE and want to continue with updated (edited) version of the
class without restarting all over.

It is not something that you would use from inside the JVM though.

Best regards,
Konstantin Kolinko

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: [OT] Deleting URLClassloader Cached Jars/Classes

2012-04-02 Thread Pid
On 02/04/2012 22:33, Konstantin Kolinko wrote:
 2012/4/3 Christopher Schultz ch...@christopherschultz.net:

 Is there a way to empty this cache, or disable caching all
 together?

 Not without implementing your own ClassLoader. You could read the code
 for WebappClassLoader to see how it's done in there.

 
 +1. You need your own class loader.

You would need your own *quite sophisticated* classloader.

This kind of thing is usually achieved with Java Agents that can rewrite
bytecode on the fly, like JavaRebel for example.


p

 I would say org.apache.jasper.servlet.JasperLoader.  It is classloader
 that is used to load JSP pages.  If the page is updated you just throw
 classloader instance away together with the classes that it loaded.
 
 In recent JVMs there is also an option to reload a class in memory
 (aka hot-swap). That is used by debuggers, when you debug your program
 in an IDE and want to continue with updated (edited) version of the
 class without restarting all over.
 
 It is not something that you would use from inside the JVM though.
 
 Best regards,
 Konstantin Kolinko
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org
 


-- 

[key:62590808]



signature.asc
Description: OpenPGP digital signature