[
https://issues.apache.org/activemq/browse/SM-1569?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45616#action_45616
]
Ivan Pryvalov commented on SM-1569:
-----------------------------------
Hi Lars!
I'm talking not about the same exchange in the same endpoint at one time....
This looks also somehow impossible to me...
But I'm talking about miltithreading. When we have one instance of some
util-class (List, Map) and few threads to modify it (add, put etc).
In case ArrayList I think everyone knows example with bad using of methods
"add" "get" "remove" in a few threads...
Simple scenario (1 - thread one, 2- thread 2):
1. add (element) ---> [ now size is 1]
2. size = getSize() ---> [return 1]
1. remove (0) ---> [now size is 0]
2. get( size-1) ---> ArrayIndexBoundException.
This example we can easy to reproduce....
But now we have HashMap..... If we think HashMap is thread-safe - that is
WRONG.
We call methods get, put, remove which influence on internal state of instance
of HashMap. And in this case we CAN NOT be sure if we have the same INTERNAL
STATE during running one thread.
I specially prepared simple example which illustrates it:
////// code
package test.hashmap;
import java.util.HashMap;
import java.util.Map;
public class TestHashMap {
private Map<String, String> map = null;
public TestHashMap(Map<String, String> map) {
super();
this.map = map;
}
public class TestOne implements Runnable {
private String id = null;
private Map<String, String> map = null;
public TestOne(String id, Map<String, String> map) {
super();
this.id = id;
this.map = map;
}
public void run() {
map.put(id, id);
String value = map.get(id);
System.out.println("get(" + id + ")=" + value);
}
}
public void runTest(int count) {
for (int i = 0; i < count; i++) {
new Thread(new TestOne(Integer.toString(i),
map)).start();
}
}
public static void main(String[] args) {
Map<String, String> map = new HashMap<String, String>();
TestHashMap testHashMap = new TestHashMap(map);
testHashMap.runTest(1000);
}
}
////// end code
After test sometimes in conlose I get something like following:
get(1)=1
get(0)=0
get(2)=2
get(3)=3
get(5)=5
get(7)=7
get(4)=4
.....
get(380)=380
get(381)=381
get(379)=379
get(384)=384
get(383)=383
get(386)=386
get(382)=null
get(388)=388
get(387)=387
get(385)=null
get(390)=390
get(389)=389
get(391)=391
get(392)=392
get(393)=393
get(395)=395
.....
get(382)=null ------> it's BAD situdation... And we can not prognose it....
Sometimes it does not apper, but sometimes it is apper...
Truly yours,
Ivan Pryvvaov.
> CleanUp tempFiles-attachments is not thread-safe
> ------------------------------------------------
>
> Key: SM-1569
> URL: https://issues.apache.org/activemq/browse/SM-1569
> Project: ServiceMix
> Issue Type: Bug
> Components: servicemix-mail
> Affects Versions: 3.3
> Environment: SMX-3.3
> Reporter: Ivan Pryvalov
> Assignee: Lars Heinemann
> Fix For: 3.3
>
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.