Github user bgutjahr commented on a diff in the pull request: https://github.com/apache/activemq-artemis/pull/1144#discussion_r108594658 --- Diff: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ActiveMQThreadPoolExecutor.java --- @@ -46,32 +45,70 @@ private static class ThreadPoolQueue extends LinkedBlockingQueue<Runnable> { private ActiveMQThreadPoolExecutor executor = null; + private int idleThreads = 0; public void setExecutor(ActiveMQThreadPoolExecutor executor) { this.executor = executor; } @Override - public boolean offer(Runnable runnable) { + public synchronized boolean offer(Runnable runnable) { --- End diff -- the synchronized is necessary to make sure the idleThreads doesn't change, which is done it the related synchronized blocks in poll and take. I also needed to make sure that no 2 offers occur in parallel. Otherwise, each offer could see one remaining idle thread and queue it's task. But only 1 task has to be be queued, for the other task a new thread has to be created. I might be able to reduce the synchronization time, but I can't avoid it. I don't think that the additional synchronization will be recognizable compared to the runtime of the tasks to be executed. The underlying LinkedBlockingQueue also uses a ReentrantLock (which I could't access). So I'm not sure if trying to optimize on that level will be recognizable and would be worth the effort.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---