mirror of https://github.com/sbt/sbt.git
Merge pull request #5641 from eatkins/completion-threads
Name threads in completion service
This commit is contained in:
commit
77a99d34df
|
|
@ -23,18 +23,25 @@ trait CompletionService[A, R] {
|
||||||
def take(): R
|
def take(): R
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
import java.util.concurrent.{
|
import java.util.concurrent.{
|
||||||
Callable,
|
Callable,
|
||||||
CompletionService => JCompletionService,
|
|
||||||
Executor,
|
Executor,
|
||||||
Executors,
|
|
||||||
ExecutorCompletionService,
|
ExecutorCompletionService,
|
||||||
|
Executors,
|
||||||
RejectedExecutionException,
|
RejectedExecutionException,
|
||||||
|
CompletionService => JCompletionService
|
||||||
}
|
}
|
||||||
|
|
||||||
object CompletionService {
|
object CompletionService {
|
||||||
|
val poolID = new AtomicInteger(1)
|
||||||
def apply[A, T](poolSize: Int): (CompletionService[A, T], () => Unit) = {
|
def apply[A, T](poolSize: Int): (CompletionService[A, T], () => Unit) = {
|
||||||
val pool = Executors.newFixedThreadPool(poolSize)
|
val i = new AtomicInteger(1)
|
||||||
|
val id = poolID.getAndIncrement()
|
||||||
|
val pool = Executors.newFixedThreadPool(
|
||||||
|
poolSize,
|
||||||
|
(r: Runnable) => new Thread(r, s"sbt-completion-thread-$id-${i.getAndIncrement}")
|
||||||
|
)
|
||||||
(apply[A, T](pool), () => { pool.shutdownNow(); () })
|
(apply[A, T](pool), () => { pool.shutdownNow(); () })
|
||||||
}
|
}
|
||||||
def apply[A, T](x: Executor): CompletionService[A, T] =
|
def apply[A, T](x: Executor): CompletionService[A, T] =
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger
|
||||||
|
|
||||||
import sbt.internal.util.AttributeKey
|
import sbt.internal.util.AttributeKey
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -119,6 +121,8 @@ object ConcurrentRestrictions {
|
||||||
private[this] def merge[A, B](m: Map[A, B], n: Map[A, B])(f: (B, B) => B): Map[A, B] =
|
private[this] def merge[A, B](m: Map[A, B], n: Map[A, B])(f: (B, B) => B): Map[A, B] =
|
||||||
n.foldLeft(m) { case (acc, (a, b)) => update(acc, a, b)(f) }
|
n.foldLeft(m) { case (acc, (a, b)) => update(acc, a, b)(f) }
|
||||||
|
|
||||||
|
private[this] val poolID = new AtomicInteger(1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a CompletionService suitable for backing task execution based on the provided restrictions on concurrent task execution.
|
* Constructs a CompletionService suitable for backing task execution based on the provided restrictions on concurrent task execution.
|
||||||
* @return a pair, with _1 being the CompletionService and _2 a function to shutdown the service.
|
* @return a pair, with _1 being the CompletionService and _2 a function to shutdown the service.
|
||||||
|
|
@ -129,11 +133,12 @@ object ConcurrentRestrictions {
|
||||||
tags: ConcurrentRestrictions[A],
|
tags: ConcurrentRestrictions[A],
|
||||||
warn: String => Unit
|
warn: String => Unit
|
||||||
): (CompletionService[A, R], () => Unit) = {
|
): (CompletionService[A, R], () => Unit) = {
|
||||||
val pool = Executors.newCachedThreadPool()
|
val id = poolID.getAndIncrement
|
||||||
(completionService[A, R](pool, tags, warn), () => {
|
val i = new AtomicInteger(1)
|
||||||
pool.shutdownNow()
|
val pool = Executors.newCachedThreadPool { r =>
|
||||||
()
|
new Thread(r, s"sbt-completion-service-pool-$id-${i.getAndIncrement()}")
|
||||||
})
|
}
|
||||||
|
(completionService[A, R](pool, tags, warn), () => { pool.shutdownNow(); () })
|
||||||
}
|
}
|
||||||
|
|
||||||
def completionService[A, R](
|
def completionService[A, R](
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue