I'm implementing a custom FutureTask
(not extending) for use in thread pools, and so on. I need special features and cannot extend directly upon FutureTask
s methods. To help me do this, I looked at the default implementation. You can see the default implementation here, if you cannot access the code:
As you can see, it uses AbstractQueuedSynchronizer
. My question is simply why? Is this class super-optimized or is it mainly the FIFO feature which is attractive? My initial idea was to implement my custom FutureTask
using an AtomicInteger
and other low-level constructs, using my average knowledge of good synchronous constructs to implement my FutureTask
optimally, so I might not want AQS
s slower features, if there are any. So are there any other features AQS
offers? Any good arguments for/against using it? This is my limited guess so far:
AQS
* Maybe the de facto standard, because it's what you should use in the general case (pro)
* Can copy most of the code (pro)
* The FIFO feature is interesting, but is it desirable for a FutureTask
? (neutral)
* Perhaps its features makes it slower than low level constructs? (con)
AtomicInteger & other low-level constructs
* Probably as fast as you can get? (pro)
* Have to implement self ((minor) con)
* No FIFO (con)