hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPASYNC-78) AbstractMultiworkerIOReactor.DefaultThreadFactory.COUNT incorrect use of volatile
Date Sun, 29 Jun 2014 01:29:26 GMT

    [ https://issues.apache.org/jira/browse/HTTPASYNC-78?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14047028#comment-14047028
] 

Sebb commented on HTTPASYNC-78:
-------------------------------

This was reported by a message to the dev list which did not get moderated through in time:


From: 王方阵 <Boyce.Wang@sky-mobi.com>
To: dev <dev@hc.apache.org>
Cc: 
Date: Wed, 25 Jun 2014 19:48:42 +0800
Subject: a bug about HttpAsyncClient.
dear,
            I meet a bug when I check threads with jstack.
"I/O dispatcher 31" prio=10 tid=0x09f0e800 nid=0x68f7 runnable [0x7dbdb000]
"I/O dispatcher 30" prio=10 tid=0x0995a000 nid=0x68f6 runnable [0x7dcdc000]
"I/O dispatcher 29" prio=10 tid=0x09958800 nid=0x68f5 runnable [0x7dddd000]
"I/O dispatcher 28" prio=10 tid=0x09956c00 nid=0x68f4 runnable [0x7dede000]
"I/O dispatcher 27" prio=10 tid=0x09fe4000 nid=0x68f3 runnable [0x7dfdf000]
"I/O dispatcher 26" prio=10 tid=0x09fe2800 nid=0x68f2 runnable [0x7e0e0000]
"I/O dispatcher 25" prio=10 tid=0x09fe1400 nid=0x68f1 runnable [0x7e1e1000]
"I/O dispatcher 13" prio=10 tid=0x09deac00 nid=0x68f0 runnable [0x7e2e2000]
"I/O dispatcher 24" prio=10 tid=0x09de9000 nid=0x68ef runnable [0x7e3e3000]
"I/O dispatcher 22" prio=10 tid=0x09fd8000 nid=0x68ee runnable [0x7e4e4000]
"I/O dispatcher 19" prio=10 tid=0x09fd6800 nid=0x68ed runnable [0x7e5e5000]
"I/O dispatcher 14" prio=10 tid=0x09b5b800 nid=0x68ec runnable [0x7e6e6000]
"I/O dispatcher 12" prio=10 tid=0x09b5a000 nid=0x68eb runnable [0x7e7e7000]
"I/O dispatcher 11" prio=10 tid=0x09b5f000 nid=0x68ea runnable [0x7e8e8000]
"I/O dispatcher 10" prio=10 tid=0x09b5d800 nid=0x68e9 runnable [0x7e9e9000]
"I/O dispatcher 2" prio=10 tid=0x09aa9400 nid=0x68e8 runnable [0x7eaea000]
"I/O dispatcher 23" prio=10 tid=0x09acd000 nid=0x68e7 runnable [0x7ebeb000]
"I/O dispatcher 21" prio=10 tid=0x09b68800 nid=0x68e6 runnable [0x7ecec000]
"I/O dispatcher 20" prio=10 tid=0x0aa0dc00 nid=0x68e5 runnable [0x7eded000]
"I/O dispatcher 18" prio=10 tid=0x0a841800 nid=0x68e4 runnable [0x7eeee000]
"I/O dispatcher 17" prio=10 tid=0x0a8d4000 nid=0x68e3 runnable [0x7efef000]
"I/O dispatcher 16" prio=10 tid=0x0a21a000 nid=0x68e2 runnable [0x7f0f0000]
"I/O dispatcher 15" prio=10 tid=0x09d08c00 nid=0x68e1 runnable [0x7f1f1000]
"I/O dispatcher 13" prio=10 tid=0x0a1b6000 nid=0x68e0 runnable [0x7f2f2000]
"I/O dispatcher 9" prio=10 tid=0x801f5000 nid=0x68df runnable [0x7f3f3000]
"I/O dispatcher 8" prio=10 tid=0x801f3800 nid=0x68de runnable [0x7f4f4000]
"I/O dispatcher 7" prio=10 tid=0x801fdc00 nid=0x68dd runnable [0x7f5f5000]
"I/O dispatcher 6" prio=10 tid=0x801fc400 nid=0x68dc runnable [0x7f6f6000]
"I/O dispatcher 5" prio=10 tid=0x7ffe8c00 nid=0x68db runnable [0x7f7f7000]
"I/O dispatcher 4" prio=10 tid=0x801ef000 nid=0x68da runnable [0x7f8f8000]
"I/O dispatcher 3" prio=10 tid=0x81bb3c00 nid=0x68d9 runnable [0x7f9f9000]
"I/O dispatcher 1" prio=10 tid=0x81b9d000 nid=0x68d8 runnable [0x7fafa000]

we can see two "I/O dispatcher 13" in the list. I found the original source in httpcomponents-asyncclient-4.0.1。
 
the code is in AbstractMultiworkerIOReactor.java at line 596-602.  the coder use volatile
in a wrong way.

 static class DefaultThreadFactory implements ThreadFactory {

private static volatile int COUNT = 0;

public Thread newThread(final Runnable r) {
return new Thread(r, "I/O dispatcher " + (++COUNT));
}

}



> AbstractMultiworkerIOReactor.DefaultThreadFactory.COUNT incorrect use of volatile
> ---------------------------------------------------------------------------------
>
>                 Key: HTTPASYNC-78
>                 URL: https://issues.apache.org/jira/browse/HTTPASYNC-78
>             Project: HttpComponents HttpAsyncClient
>          Issue Type: Bug
>            Reporter: Sebb
>            Priority: Minor
>
> AbstractMultiworkerIOReactor.DefaultThreadFactory.COUNT is a volatile int which is incremented
using ++COUNT.
> This is not thread-safe; multiple threads can end up with the same value for COUNT.
> Should probably use AtomicInt instead



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message