Skip to content

Commit

Permalink
Moved the threadpool responsible for the timer tasks that kill future…
Browse files Browse the repository at this point in the history
…s that time out (for .within)

This is because in an extreme load scenario, the time tasks will be queued so behind the actual threads execution tasks that they won't execute at all, causing starvation.
  • Loading branch information
shaiyallin committed Feb 20, 2014
1 parent 9d62454 commit d52809a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/scala/com/wix/async/FuturePerfect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.wix.async
import scala.concurrent.duration.Duration
import com.twitter.util._

import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.{Executors, ExecutorService, ScheduledExecutorService}
import FuturePerfect._
import Implicits._

Expand All @@ -14,10 +14,10 @@ import Implicits._

trait FuturePerfect extends Reporting[Event] {

def executorService: ScheduledExecutorService
implicit lazy val timer: Timer = new ScheduledExecutorServiceTimer(executorService)
def executorService: ExecutorService
implicit lazy val timer: Timer = new ScheduledExecutorServiceTimer(Executors.newScheduledThreadPool(10))

class AsyncExecution[T](executorService: ScheduledExecutorService,
class AsyncExecution[T](executorService: ExecutorService,
timeout: Duration,
retryPolicy: RetryPolicy,
onTimeout: TimeoutHandler,
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/com/wix/async/FuturePerfectTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class FuturePerfectTest extends SpecificationWithJUnit with Mockito with NoTimeC
class AsyncScope extends Scope with FuturePerfect {

val reporter = mock[Reporter[Event]]
val executorService = Executors.newScheduledThreadPool(4)
val executorService = Executors.newFixedThreadPool(4)
register(reporter)

class Bar {
Expand Down

0 comments on commit d52809a

Please sign in to comment.