doanduyhai/Achilles — pull request #154 by obourgain (2014-11-16 11:32:13+00:00)
Title: avoid intensive use of the executor

This pull requests void using too much the executor to process trivial operation like mapping rows, wrap in a proxy etc.

For now I will suggest against merging this PR as one issue remains. With the design I propose, all transformations and triggers are performed when get() is called on the future.
In sync mode it is ok as the PersistenceManager performs a get() on the future before returning.
In async mode, for find-like method, it should be ok as the client will want to get the result, but for insert, it can be an issue, because the client may not call get() on the future, and then post insert interceptors won't be called.
Maybe using the executor in async mode to perform the get() one the future to ensure that interceptors are called would be almost ok. One new issue would be that with the current code one thread per future is required as some operation may take a lot longer than others. A solution is to wrap the executor in a CompletionService, that is a Queue-like structure for Futures but instead of being FIFO, it returns the Future when they are done.