powered by Jive Software

How to use a custom Executor for AbstractComponent



org.xmpp.component.AbstractComponent internally uses a pretty rigid Executor for handling all packets sent to the component:

this.executor = new ThreadPoolExecutor(this.maxThreadPoolSize, this.maxThreadPoolSize, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue(this.maxQueueSize));

We now have the issue, that we want to customize the Executor beyond setting max pool size and max queue size.

The issue is, that packets queue up until the queue is full and only then a new thread is created. So one “slow” packet can block all following other packets, unless the queue is full, in which case a second thread helps with the queue.
Clients may wait very long for their IQ results then, if there’s one “malicious” IQ reqeust in the queue, which processes a long time.

The issue with this default behavior of the ThreadPoolExecutor is also described here: https://stackoverflow.com/q/19528304/2907078

There’s also a solution (prefer spawning new threads, before queuing), but it’s impossible to set a custom Executor in AbstractComponent.

It would be great, if this would be more customizable.


Well, you don’t have to extend AbstractComponent. You could simply copy the code, call it “MyAbstractComponent” and extend from that, making the changes you want.

If you think your changes could be more widely applicable, a PR with them in to the Tinder project would be appreciated. Probably the simplest change would be to place the “new ThreadPoolExecutor(…)” code in to a protected method, protected ThreadPoolExecutor createThreadPoolExecutor() that could be over-ridden when needed.