Ben Hammond
11/20/2020, 12:04 PMFixedThreadPool
executor within a synchronized block, and I pass in a ThreadFactory Lambda fun;
when the threadfactory function is subsequently evaluated, will the Monitor lock be acquired?
(I am hoping/expecting not - otherwise I would put the sychronized inside the ThreadFactory fn)Ben Hammond
11/20/2020, 12:08 PMChantry Cargill
11/20/2020, 12:17 PMBen Hammond
11/20/2020, 12:40 PMvar myExec: ExecutorService? = null
fun createOrReturnMyExec() {
synchronized(this) {
if ((myExec == null) || (myExec!!.isShutdown)) {
myExec = Executors.newFixedThreadPool(10) {runnable ->
/*
* Is this going to have the synchronized(this) monitor acquired when it finally gets run?
* (I hope not)
*/
Thread(runnable)
}
}
}
}
Ben Hammond
11/20/2020, 12:42 PMChantry Cargill
11/20/2020, 12:50 PMBen Hammond
11/20/2020, 12:51 PMBen Hammond
11/20/2020, 12:52 PMBen Hammond
11/20/2020, 12:52 PMChantry Cargill
11/20/2020, 12:52 PMBen Hammond
11/20/2020, 12:56 PMBen Hammond
11/20/2020, 12:57 PMsynchronised
is very much less helpful than I'd hoped - all it means is the coroutine all interleave themselves on the same Monitor-owning threadBen Hammond
11/20/2020, 12:57 PM