-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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