FAQ

On 4/17/07, Christopher Schultz wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Craig,

Craig McClanahan wrote:
Craig McClanahan wrote:
Yep ... it's magic :-).

Actually, what happens is that the servlet container provides a
mechanism to acquire the ClassLoader instance for the web application
itself, from which you can load application classes no matter where
the caller is located. For instance, when Struts loads an action
class, it does something like this (plus some exception catching, of
course):

String actionClassName = ...;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class actionClass = cl.loadClass(actionClassName);
I thought that the server created and started those threads
independently of the webapp being used.
Yes, it does ... although there is no restriction that a particular
thread be used *only* for a particular application. Generally, the
server will pool the threads across all active apps.
I've never used
Thread.getContextClassLoader... is that something that the server sets
when it handles a request -- for purposes such as this?
Yes, that's exactly what it is for.

Craig
The container guarantees that the context class loader for a thread is
set correctly, before it enters your servlet, filter, or listener.
I guess so... ;)
There is indeed no way to search down the hierarchy, which is why the
context class loader convention was created. As you examine libraries
for potentially putting them into a shared class loader, look for code
that does this kind of thing.
Cool. Thanks for the explanation, Craig.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGJS4d9CaO5/Lv0PARAqzKAKC4t0HR31h8KaLX471socJ7rbNphQCfWpAM
IrvvDVTjDYBpzob6TtwoGl4=
=Qq2L
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 9 | next ›
Discussion Overview
groupuser @
categoriesstruts
postedApr 17, '07 at 2:12a
activeApr 20, '07 at 3:30p
posts9
users4
websitestruts.apache.org
irc#struts

People

Translate

site design / logo © 2017 Grokbase