
org.analogweb.scala.Execution.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of analogweb-scala_2.11 Show documentation
Show all versions of analogweb-scala_2.11 Show documentation
Analogweb Framework is tiny, simple, and pluggable web framework.
The newest version!
package org.analogweb.scala
import java.util.concurrent.ForkJoinPool
import scala.util.Try
import scala.concurrent.ExecutionContext
object Execution {
object Implicits {
implicit val defaultContext: ExecutionContext =
create
def create = {
def getInt(name: String, f: String => Int): Int =
Try(f(System.getProperty(name)))
.getOrElse(Runtime.getRuntime.availableProcessors)
def range(floor: Int, desired: Int, ceiling: Int): Int =
if (ceiling < floor)
range(ceiling, desired, floor)
else
scala.math.min(scala.math
.max(desired, floor),
ceiling)
val desiredParallelism =
range(
getInt("analogweb.threads.min", _.toInt),
getInt(
"analogweb.threads", {
case n if Some(n) == None | n == "" =>
Runtime.getRuntime.availableProcessors
case s if s.charAt(0) == 'x' =>
(Runtime.getRuntime.availableProcessors * s
.substring(1)
.toDouble).ceil.toInt
case other =>
other.toInt
}
),
getInt("analogweb.threads.max", _.toInt)
)
ExecutionContext
.fromExecutorService(new ForkJoinPool(desiredParallelism))
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy