Hello, I’m trying to use an `Executors.newFixedThr...
# coroutines
p
Hello, I’m trying to use an
Executors.newFixedThreadPool(8)
to create a pool of threads that are meant to indefinitely process incoming SQS messages. It seems from my tests that tasks are submitted constantly to the pool without waiting for one or more of the 8 allocated threads to finish. I’m not using shutdown as I do not want to shutdown this pool but instead use it indefinitely but wait when it is full. Any ideas?
c
As documented,
newFixedThreadPool
uses an unbounded queue for submitted tasks. You can submit all the tasks and then shutdown the pool and await termination (blocking until all are complete). If you desire different behaviour you can change the queueing strategy here. Or use Kotlin coroutines for lighter-weight concurrency.
p
Can I launch tasks without joining in a limited coroutine context? I’m reading about
Dispatchers.IO.limitedParallelism
atm, but despite being at 1.6.3 Idea complains of it not existing….
g
Are you sure that it complains it’s not existing, not complaining that it’s experiment API?
but wait when it is full
Could you explain a bit more? Do you want to prevent adding new tasks to the queue if it already has 8? And suspend for this?