@@ -9,6 +9,8 @@ import org.evomaster.core.problem.rest.RestResponseFeeder
99import org.evomaster.core.problem.rest.param.PathParam
1010import org.evomaster.core.search.gene.Gene
1111import org.evomaster.core.search.gene.ObjectGene
12+ import java.util.concurrent.ConcurrentHashMap
13+ import java.util.concurrent.ConcurrentLinkedDeque
1214
1315/* *
1416 * Service to keep track of data values associated with a string key.
@@ -43,9 +45,8 @@ class DataPool() {
4345 private lateinit var randomness: Randomness
4446
4547
46- private val pool : MutableMap <String , ArrayDeque <String >> = mutableMapOf ()
48+ private val pool : ConcurrentHashMap <String , ConcurrentLinkedDeque <String >> = ConcurrentHashMap ()
4749
48- private val stemmer = PorterStemmer ()
4950
5051 internal constructor (_config : EMConfig , _randomness : Randomness ) : this (){
5152 config = _config
@@ -60,8 +61,7 @@ class DataPool() {
6061 }
6162
6263 private fun stem (s : String ) : String {
63- stemmer.reset()
64- return stemmer.stem(s)
64+ return PorterStemmer ().stem(s)
6565 }
6666
6767 fun applyTo (gene : Gene ) : Boolean {
@@ -96,16 +96,18 @@ class DataPool() {
9696
9797 fun addValue (key : String , data : String ){
9898
99- val queue = pool.getOrPut(normalize(key)) { ArrayDeque () }
99+ synchronized(pool) {
100+ val queue = pool.getOrPut(normalize(key)) { ConcurrentLinkedDeque () }
100101
101- if (queue.contains(data)){
102- return // already there
103- }
102+ if (queue.contains(data)) {
103+ return // already there
104+ }
104105
105- if (queue.size == config.maxSizeDataPool){
106- queue.removeFirst()
106+ if (queue.size == config.maxSizeDataPool) {
107+ queue.removeFirst()
108+ }
109+ queue.addLast(data)
107110 }
108- queue.addLast(data)
109111 }
110112
111113 /* *
@@ -126,6 +128,10 @@ class DataPool() {
126128 */
127129 fun extractValue (key : String , objectName : String? = null) : String? {
128130
131+ // We synchronized insertions, as that might lead to inconsistencies... but read operation should be (hopefully)
132+ // fine, concurrent as anyway the pool is
133+ // synchronized(pool)
134+
129135 if (pool.isEmpty()){
130136 return null
131137 }
0 commit comments