I have successfully created a Guice binding annotation to inject single threaded java.util.concurrent.ExecutorService instances into a constructor.
here is an exampl
You can't. That's not how binding annotations are intended to be used... the parameter would only serve to differentiate an ExecutorService
bound with @MultiThreaded(poolSize = 5)
from one bound with @MultiThreaded(poolSize = 2)
. It's not metadata to help configure a Provider
.
If you inject something annotated with @MultiThreaded(poolSize = 5)
, you need to have bound something with the annotation @MultiThreaded(poolSize = 5)
. If you then want to change the pool size you're using in all those places, you need to change poolSize = 5
to poolSize = 4
in both the place(s) where you bind it and in all the places you inject it. This doesn't make much sense to me.
Instead of binding ExecutorService
s by how many threads they have in their thread pool, you should bind them according to what you want to use them for. Then you can adjust the numbers of threads each one uses in one place.