You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dola Woolfe <do...@yahoo.com> on 2009/05/19 18:28:46 UTC
How to hot swap classes?
Hi,
When developing a web application I change my classes all the time and therefore need to restart tomcat every time. Is there a way to avoid restarting tomcat? Could it hot swap the new class in?
(It does somehow hot swap recompiled .jsp's doesn't it?)
Many thanks in advance,
Dola
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: How to hot swap classes?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net]
> Subject: Re: How to hot swap classes?
>
> Did you mean "a separate ClassLoader for all the JSPs"?
Not quite, but what I said was incomplete. From looking at the code, it appears that each context gets its own instance of JasperLoader (a subclass of URLClassLoader) when the first JSP for the context is referenced. That classloader will continue to be used until a previously compiled but now updated JSP is encountered. At that point, the existing JasperLoader for the context is discarded, and a new one created. The following code is in JspCompilationContext.java, at line 580 in 6.0.18:
public void compile() throws JasperException, FileNotFoundException {
createCompiler();
if (jspCompiler.isOutDated()) {
try {
jspCompiler.removeGeneratedFiles();
jspLoader = null;
jspCompiler.compile();
jsw.setReload(true);
jsw.setCompilationException(null);
} catch (JasperException ex) {
// Cache compilation exception
jsw.setCompilationException(ex);
throw ex;
} catch (Exception ex) {
JasperException je = new JasperException(
Localizer.getMessage("jsp.error.unable.compile"),
ex);
// Cache compilation exception
jsw.setCompilationException(je);
throw je;
}
}
}
The new instance of JasperLoader is created by the method getJspLoader() at line 177 of the same file. Note that your grep would not have found the JasperLoader due to its not using ClassLoader in its name.
Also, the JSP classloaders do not seem to appear in any JMX objects, unfortunately.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Re: How to hot swap classes?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Chuck,
On 5/19/2009 12:37 PM, Caldarale, Charles R wrote:
>> From: Dola Woolfe [mailto:dolachin@yahoo.com] Subject: How to hot
>> swap classes?
>>
>> When developing a web application I change my classes all the time
>> and therefore need to restart tomcat every time.
>
> No, you only need to restart the webapp; there's no need to restart
> Tomcat.
>
>> Could it hot swap the new class in?
>
> No, but it's something that some of us have talked about.
>
>> (It does somehow hot swap recompiled .jsp's doesn't it?)
>
> There's a separate classloader for each JSP, but just one classloader
> for the rest of the webapp.
Did you mean "a separate ClassLoader for all the JSPs"?
I ran jmap -histo while loading several JSP files that had never been
loaded (I know, because I copied them into the webapp's deployment
directory just for this test) and no additional ClassLoaders were allocated:
jmap -histo 1430 | grep ClassLoader
125: 22 1232 sun.reflect.DelegatingClassLoader
314: 1 160
org.apache.catalina.loader.WebappClassLoade
340: 4 128 java.lang.ClassLoader$NativeLibrary
437: 1 72 sun.misc.Launcher$ExtClassLoader
443: 1 72
org.apache.catalina.loader.StandardClassLoader
447: 1 72 sun.misc.Launcher$AppClassLoader
495: 1 56 java.util.ResourceBundle$RBClassLoader
522: 3 48
com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport$LoaderEntry
564: 2 40
[Lcom.sun.jmx.mbeanserver.ClassLoaderRepositorySupport$LoaderEntry;
650: 1 24
com.sun.jmx.mbeanserver.ClassLoaderRepositorySupport
723: 1 16
com.sun.jmx.mbeanserver.SecureClassLoaderRepository
805: 1 8 java.net.URLClassLoader$7
None of those numbers increased as I loaded more JSPs.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkoS/+oACgkQ9CaO5/Lv0PBR9gCgg/uLYLCgYaHc53DxQMwQ62zE
FGAAoK7kSZMzQuJN8RoKsXhEdvYKY0ln
=V4Z4
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: How to hot swap classes?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dola Woolfe [mailto:dolachin@yahoo.com]
> Subject: How to hot swap classes?
>
> When developing a web application I change my classes all the time and
> therefore need to restart tomcat every time.
No, you only need to restart the webapp; there's no need to restart Tomcat.
> Could it hot swap the new class in?
No, but it's something that some of us have talked about.
> (It does somehow hot swap recompiled .jsp's doesn't it?)
There's a separate classloader for each JSP, but just one classloader for the rest of the webapp.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to hot swap classes?
Posted by Ken Bowen <kb...@als.com>.
I use MyEclipse (a commercial extension of Eclipse -- pretty
inexpensive). It supports hot swapping of classes, jsps, css, js --
pretty much everything but things like web.xml, for which Tomcat must
be restarted (no surprise).
On May 19, 2009, at 12:28 PM, Dola Woolfe wrote:
>
> Hi,
>
> When developing a web application I change my classes all the time
> and therefore need to restart tomcat every time. Is there a way to
> avoid restarting tomcat? Could it hot swap the new class in?
>
> (It does somehow hot swap recompiled .jsp's doesn't it?)
>
> Many thanks in advance,
>
> Dola
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to hot swap classes?
Posted by Anurag Kapur <an...@gmail.com>.
Refer : http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
reloadable
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and
/WEB-INF/lib for changes, and automatically reload the web application if a
change is detected. This feature is very useful during application
development, but it requires significant runtime overhead and is not
recommended for use on deployed production applications. That's why the
default setting for this attribute is *false*. You can use the
Manager<http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html>web
application, however, to trigger reloads of deployed applications on
demand.
Regards
Anurag
------------------------------------------------------------------
Anurag Kapur
Associate - Technology,
Sapient Corporation.
+44 (0) 7514 996 586
http://www.linkedin.com/in/anuragkapur
------------------------------------------------------------------
Sent from London, Eng, United Kingdom
On Tue, May 19, 2009 at 5:28 PM, Dola Woolfe <do...@yahoo.com> wrote:
>
> Hi,
>
> When developing a web application I change my classes all the time and
> therefore need to restart tomcat every time. Is there a way to avoid
> restarting tomcat? Could it hot swap the new class in?
>
> (It does somehow hot swap recompiled .jsp's doesn't it?)
>
> Many thanks in advance,
>
> Dola
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>