-
Bug
-
Resolution: Done
-
Major
-
7.1.0.DR11, 7.1.0.DR18
-
None
During investigation of test failures in Artemis test suite I've noticed that ActiveMQThreadPoolExecutor sometimes doesn't allocate new Worker for a task even if maxPoolSize = 16 and there are only 3 tasks to execute. Instead the task is queued and it waits until some worker finishes its job.
I think the problem is in offer method.
@Override public boolean offer(Runnable runnable) { int poolSize = executor.getPoolSize(); // If the are less threads than the configured maximum, then the tasks is // only queued if there are some idle threads that can run that tasks. // We have to add the queue size, since some tasks might just have been queued // but not yet taken by an idle thread. if (poolSize < executor.getMaximumPoolSize() && (size() + executor.getActive()) >= poolSize) return false; return super.offer(runnable); }
There are 3 variables which are compared with themselves - executor.getPoolSize(), size(), executor.getActive() - without any synchronization. It may happen that the if condition is false just because some variable hasn't been updated yet.
I've created reproducer [1] for this issue. You can run it from branch [2] using following commands.
git clone https://github.com/dudaerich/activemq-artemis cd activemq-artemis git checkout ActiveMQThreadPoolExecutorTest mvn test -Dtest=ActiveMQThreadPoolExecutorTest -Ptests -DfailIfNoTests=false -Drat.ignoreErrors=true 2>&1 | tee log
[1] https://github.com/dudaerich/activemq-artemis/blob/a0eb0ea9caaf22a9d031d480625a638a2e0f300d/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/util/ActiveMQThreadPoolExecutorTest.java
[2] https://github.com/dudaerich/activemq-artemis/commits/ActiveMQThreadPoolExecutorTest
- is duplicated by
-
JBEAP-10006 Thread pool executor occasionally misses to create a new thread
- Closed
- is incorporated by
-
JBEAP-11000 Upgrade Artemis 1.5.5.jbossorg-001
- Closed
- relates to
-
ARTEMIS-1078 Loading...