Hi Oleg,
On Jun 2, 2010, at 4:38am, Oleg Kalnichevski wrote:
On Tue, 2010-06-01 at 22:55 +0200, Jakub wrote:
Hey folks,
I was trying out the ThreadSafeClientConnManager example from
documentation, together with java executor framework and the
executor.shutdown() function. Is it ok to exit threads running
httpClient.execute like this ? I'm getting this stack trace for
each thread shutdown like this. They are usually refused
connections... appreciate any advice, Jakub
http://pastebin.com/eGjzQAy9
http://pastebin.com/F80VRZxX
Executor#shutdown() terminates worker threads by interrupting them.
While this might work, it usually can result in all sorts of funny
exceptions. Moreover, as far as I know some I/O operations cannot be
reliably unblocked by just interrupting the thread.
Yes, this is what we're seeing when (for example) a very slow server
is trickling back data. The interrupt does nothing.
It is recommended to
use HttpUriRequest#abort method to abort requests still being executed
and then terminate and join worker threads.
I'm trying to figure out how to map this advice onto what I've got in
Bixo:
- I've got a bunch of fetch tasks being executed in threads using
Java's ThreadPoolExecutor.
- Each task uses the same DefaultHttpClient with a
ThreadSafeClientConnManager to execute GetMethod requests.
So when I decide that some of these fetch tasks need to be terminated:
1. What's the right way to get the list of active HttpUriRequest
objects that need to be aborted? I assume I'll need to keep track of
this myself, in some ThreadLocal storage. I don't see a way to get the
set of active requests back from either HttpClient or the connection
manager.
2. I assume it's safe to call the HttpUriRequest.abort() method from
my main thread, while a worker thread is busy calling any method for
this same object (including abort) at the same time.
Thanks!
-- Ken
java.lang.Throwable: java.io.InterruptedIOException
at tools.proxies.GetThread.run(GetThread.java:88)
at java.lang.Thread.run(Thread.java:619)
at java.util.concurrent.ThreadPoolExecutor
$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.InterruptedIOException
at
org
.apache
.http
.impl
.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:
392)
at
org
.apache
.http
.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at
org
.apache
.http
.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:731)
at
org
.apache
.http
.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:709)
at
org
.apache
.http
.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:700)
at tools.proxies.GetThread.run(GetThread.java:65)
... 4 more
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer
$
ConditionObject
.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:1899)
at java.util.concurrent.locks.AbstractQueuedSynchronizer
$ConditionObject.await(AbstractQueuedSynchronizer.java:1934)
at
org
.apache.http.impl.conn.tsccm.WaitingThread.await(WaitingThread.java:
158)
at
org
.apache
.http
.impl
.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:
331)
at org.apache.http.impl.conn.tsccm.ConnPoolByRoute
$1.getPoolEntry(ConnPoolByRoute.java:228)
at
org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager
$1.getConnection(ThreadSafeClientConnManager.java:172)
at
org
.apache
.http
.impl
.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:
390)
... 9 more
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
--------------------------------------------
<http://ken-blog.krugler.org>
+1 530-265-2225
--------------------------------------------
Ken Krugler
+1 530-210-6378
http://bixolabs.com
e l a s t i c w e b m i n i n g