rahulrav
07/08/2018, 5:29 PMprivate fun defaultExecutor(): ThreadPoolExecutor {
val maxPoolSize = Runtime.getRuntime().availableProcessors() * 3
val keepAliveTime = 2L // in seconds
val queue = LinkedBlockingQueue<Runnable>()
return ThreadPoolExecutor(0, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue, ThreadManager.currentRequestThreadFactory())
}
Note the use of the ThreadManager.currentThreadRequestFactory()
.
Every time I invoke a suspend
function I ensure that it is accompanied by a withContext(...)
which uses the above defined coroutine dispatcher.
I see that sometimes, I get `Exception`s on App Engine, claiming I am trying to get an instance of supporting services (like Datastore or Memcache) on a thread which was not created by their thread factory (ThreadManager
). This typically happens in a coroutine's resume
method. Any ideas on what I might be doing wrong ?elizarov
07/08/2018, 5:39 PMcurrentThreadRequestFactory
. Can you given a link to its docs?louiscad
07/08/2018, 6:26 PMelizarov
07/08/2018, 6:43 PMReturns a ThreadFactory that will create threads scoped to the current request.
elizarov
07/08/2018, 6:44 PMlouiscad
07/08/2018, 6:57 PMwithContext(ThreadManager.currentRequestThreadFactory()) { ... /* Code accessing to the supporting services like Memcache or Datastore. */ }
rahulrav
07/08/2018, 11:21 PM