stevedlawrence commented on code in PR #879:
URL: https://github.com/apache/daffodil/pull/879#discussion_r1063602691
##########
daffodil-lib/src/main/scala/org/apache/daffodil/util/Coroutines.scala:
##########
@@ -20,10 +20,25 @@
import org.apache.daffodil.exceptions.UnsuppressableException
import java.util.concurrent.ArrayBlockingQueue
+ import java.util.concurrent.Executors
+
+ import scala.concurrent.ExecutionContext
+ import scala.concurrent.Future
import scala.util.Failure
import scala.util.Success
import scala.util.Try
+ object Coroutine {
+ val executionContext = new ExecutionContext {
+ private val threadPool = Executors.newCachedThreadPool()
+ def execute(runnable: Runnable): Unit = threadPool.submit(runnable)
Review Comment:
> How is the thread pool eventually closed, or does this executionContext
stay around as long as the program keeps running?
Yep, the JavaDoc mentions the same 60 second inactivity before throwing away
a thread. So in low activity environments the threads are automatically
discarded. We lose the performance gains, but if it's low activity I would
think lower performance would be fine.
> How does Daffodil guarantee that only a small number of coroutine threads
are used at any time?
Is this a guarantee we want to make?
There is only ever going to be one thread per active call to SAX unparse. So
the only way to hit the INT_MAX limit is to invoke INT_MAX SAX unparses at the
same time in parallel. I imagine trying to do that is going to cripple the
system regardless of whether we're using coroutines/SAX or not.
I think we just rely on the user to limit how many parallel unparse calls
they think is reasonable, and we'll spawn one thread for each of those for our
thread pool. If those users don't limit it any way and allow INT_MAX parallel
unparses, then that's on them and we'll do our best to keep up.
If we wanted, we could add allow callers to pass in an execution context to
the `newContentHandlerInstance` function, which would give them control over
how threads are spawned. I'm not against this, but I'm not sure if people would
ever really use it...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]