Skip to content

Instantly share code, notes, and snippets.

@ahinchman1
Last active October 28, 2022 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahinchman1/ca2af3708d077ba0cd59782b18c721bb to your computer and use it in GitHub Desktop.
Save ahinchman1/ca2af3708d077ba0cd59782b18c721bb to your computer and use it in GitHub Desktop.
In this code snippet, a ThreadPoolExecutor is statically saved within a singleton object with Dagger 2.
import java.util.concurrent.*
private val threadFactory = object : ThreadFactory {
private val count = AtomicInteger(1)
override fun newThread(r: Runnable): Thread = Thread(r, "Thread #${count.getAndIncrement()}")
}
@Singleton
class TopologicalProcessor {
/* Removed for brevity */
companion object {
var tileMapThreadPoolExecutor = ThreadPoolExecutor(
corePoolSize = 3,
maximumPoolSize = 3,
keepAliveTime = 0L,
unit = TimeUnit.SECONDS,
workQueue = LinkedBlockingQueue<Runnable>(),
threadFactory = threadFactory
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment