-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.scala
45 lines (36 loc) · 987 Bytes
/
Main.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.github.ondrejspanel.parFuture
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object Main {
def hotSleep(ms: Int): Unit = {
val now = System.currentTimeMillis()
while (System.currentTimeMillis() < now + ms) {}
}
def main(args: Array[String]): Unit = {
val stateCount = 50
val state = (0 until stateCount).par
val triggerIssue = true
(0 until 1000).foreach { i =>
hotSleep(25)
val innerScopeBeg = System.currentTimeMillis()
if (!triggerIssue) {
Future {
hotSleep(205)
}
}
state.foreach { x =>
if (triggerIssue && x == 0) {
Future {
hotSleep(205)
}
}
hotSleep(2)
}
val innerScopeEnd = System.currentTimeMillis()
val duration = innerScopeEnd - innerScopeBeg
if (duration >= 200) {
println(s"Suspicious background duration $duration")
}
}
}
}