ASF Bugzilla – Attachment 26564 Details for
Bug 50642
keepAliveProtection doesn't work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Servlet that should trigger this thread to be created
HttpClientServlet.java (text/java), 2.64 KB, created by
Christopher Schultz
on 2011-01-27 12:43:04 UTC
(
hide
)
Description:
Servlet that should trigger this thread to be created
Filename:
MIME Type:
Creator:
Christopher Schultz
Created:
2011-01-27 12:43:04 UTC
Size:
2.64 KB
patch
obsolete
>import java.io.IOException; >import java.io.PrintWriter; >import java.io.OutputStreamWriter; > >import javax.servlet.ServletException; >import javax.servlet.http.HttpServlet; >import javax.servlet.http.HttpServletRequest; >import javax.servlet.http.HttpServletResponse; > >import java.lang.reflect.Field; >import java.lang.reflect.Method; >import java.net.URL; >import java.net.URLClassLoader; >import sun.net.www.http.HttpClient; >import sun.net.www.http.KeepAliveCache; > >public class HttpClientServlet > extends HttpServlet >{ > public void init() > throws ServletException > { > log("HttpClientServlet.init: CCL=" + Thread.currentThread().getContextClassLoader()); > } > > public void service(HttpServletRequest request, > HttpServletResponse response) > throws ServletException, IOException > { > log("HttpClientServlet.service: CCL=" + Thread.currentThread().getContextClassLoader()); > > try > { > printThreadStatus(response.getWriter()); > > startKeepAliveThread(); > > printThreadStatus(response.getWriter()); > } > catch (Exception e) > { > throw new ServletException("Could not toy with HttpClient", e); > } > } > > public static void printThreadStatus(PrintWriter out) > throws Exception > { > final Field kac = HttpClient.class.getDeclaredField("kac"); > kac.setAccessible(true); > final Field keepAliveTimer = KeepAliveCache.class > .getDeclaredField("keepAliveTimer"); > keepAliveTimer.setAccessible(true); > > final Thread t = (Thread) keepAliveTimer.get(kac.get(null)); > > out.println("KeepAliveThread: " + t > + ", cl=" + (null == t ? "null" : t.getContextClassLoader().toString())); > } > > public static void startKeepAliveThread() > throws Exception > { > HttpClient client = HttpClient.New(new URL("http://www.google.com/")); > > // Call client.putInKeepAliveCache(); > Method m = HttpClient.class.getDeclaredMethod("putInKeepAliveCache", (Class[])null); > m.setAccessible(true); > m.invoke(client, (Object[])null); > } > > public static void main(String[] args) > throws Exception > { > ClassLoader cl = new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()); > Thread.currentThread().setContextClassLoader(cl); > > PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); > > printThreadStatus(out); > > startKeepAliveThread(); > > printThreadStatus(out); > > out.flush(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 50642
:
26541
| 26564 |
26566