How to manage executors

It's not infrequent in my practice that software I develop grows big and complex, and various parts of it use executors in their own way. From the performance point of view it would be better to use different thread pool configurations at each part. But from the maintainability and code-usability points it would be more preferable if all things related to threads, concurrency and CPU-utilization were kept and configured at some centralized place.

Having each class which needs some concurrent execution or scheduling create its own thread pool is not OK, because it is hard to control their life-cycles and overall number of threads.

Creating some kind of ExecutorManager and passing one thread pool around the application is not OK either, because, depending on type of the task and submitting rate, inappropriately configured combination of working queue and thread pool size can harm performance really bad.

So the question is: are there some common approaches that address this issue?

Answers


I would create 2 or 3 threadPools that can be configured differently depending on the tasks they execute, if there are more than 3 different concurrent actions you have a bigger problem.

The pools can be injected when needed (e.g. by name), additionally I would create an annotation to execute a defined method with a specific pool/executor using AOP (e.g. aspectj).

The annotation resolver should have access to all the pools/executors and submit the task using the one specified in the annotation.

For example:

@Concurrent ("pool1")
public void taskOfTypeOne() {
}

@Concurrent ("pool2")
public void taskOfTypeTwo() {
}

Need Your Help

User-defined literals (Extended literals) of C++11… which compilers support it?

c++ metaprogramming c++11 user-defined-literals

In another thread I introduced some techniques we would use for Model-Driven-Development in C++ once C++11 features, in particular user-defined literals, are available. I just revised the plans for...

Javascript callbacks within an object

javascript jquery javascript-events twitter-bootstrap

I'm writing a Javascript app that is getting an HTML document via AJAX, then needs to process it to attach event listeners (specifically, Bootstrap popovers) to the elements inside it. I'm having

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.