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
package akka.dispatch | |
import com.typesafe.config.Config | |
object PriorityThreadsDispatcher { | |
/** | |
* Configuration key under which int value should be placed. | |
*/ | |
val threadPriorityConfigKey = "thread-priority" | |
} |
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
package akka.dispatch | |
/** | |
* Composition over [[DefaultDispatcherPrerequisites]] that replaces thread factory with one that allow to configure thread priority. | |
* | |
* @param newThreadPriority priority that will be set to each newly created thread | |
* should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10) | |
*/ | |
class PriorityThreadsDispatcherPrerequisites(prerequisites: DispatcherPrerequisites, newThreadPriority: Int) extends DefaultDispatcherPrerequisites( | |
eventStream = prerequisites.eventStream, |
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
package akka.dispatch | |
import java.util.concurrent.ThreadFactory | |
/** | |
* Composition over the [[DispatcherPrerequisites.threadFactory]] that set priority for newly created threads. | |
* | |
* @param newThreadPriority priority that will be set to each newly created thread | |
* should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10) | |
*/ |
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
# Low priority threads protects system from CPU starvation. | |
low-priority-threads-dispatcher { | |
# For more details please see documentation of this class. | |
type = akka.dispatch.PriorityThreadsDispatcher | |
executor = "thread-pool-executor" | |
# Priority of threads in this thread pool, should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10). | |
thread-priority = 1 |
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
val lowPriorityThreadsDispatcherName = "low-priority-threads-dispatcher" | |
val lowPriorityThreadsExecutionContext = play.libs.Akka.system.dispatchers.lookup(lowPriorityThreadsDispatcherName) | |
Future { | |
require(Thread.currentThread.getPriority == Thread.MIN_PRIORITY, s"current thread's priority should be ${Thread.MIN_PRIORITY} but it is ${Thread.currentThread.getPriority}") | |
1 + 1 // do something that would be executed on low pririty thread | |
}(lowPriorityThreadsExecutionContext) |
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
/** | |
* [[ExecutionContext]] that will execute actions in calling thread (and by that making them blocking). | |
*/ | |
class CallingThreadExecutionContext extends ExecutionContext { | |
override def execute(runnable: Runnable): Unit = runnable.run | |
override def reportFailure(t: Throwable): Unit = throw t | |
} |
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
package scala.concurrent | |
import scala.concurrent.duration._ | |
import org.scalatest.FeatureSpec | |
class FutureStackTraceTest extends FeatureSpec { | |
ignore("stack trace of Future") { | |
implicit val executionContext = scala.concurrent.ExecutionContext.Implicits.global |
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
package scala.concurrent | |
import scala.util.{ Try, Success } | |
object FutureUtils { | |
/** | |
* @return resulted future will be completed when all passed futures will be completed (either with Success or Future) | |
*/ | |
def completeAll[T](fs: Future[T]*)(implicit ec: ExecutionContext): Future[Seq[Future[T]]] = Future.successful(fs).flatMap { fs => |
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
package scala.concurrent | |
import duration._ | |
import scala.util.{ Success, Try } | |
import org.scalatest.FeatureSpec | |
/** | |
* #scala45pl http://www.meetup.com/WarszawScaLa/events/225320171/ | |
* | |
* Also during this presentation: |
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
object Build extends sbt.Build { | |
implicit val artifactConfig = ArtifactConfig( | |
name = "lift-problem", | |
organization = "org.stanek", | |
version = "0.1.0-SNAPSHOT" | |
) | |
// ==== projects definition |
OlderNewer