0
在Windows 7 我在斯卡拉/播放框架新手玩2.4,我有如下一個動作:奇怪的行爲
def delay = Action.async { request =>
println(new Date() + "-1-" + Thread.currentThread().getId)
val delayed = play.api.libs.concurrent.Promise.timeout("Delayed", 10.seconds)
println(new Date() + "-2-" + Thread.currentThread().getId)
val result = delayed.map{
println(new Date() + "-3-" + Thread.currentThread().getId)
Ok(_)
}
println(new Date() + "-4-" + Thread.currentThread().getId)
result
}
我希望執行順序應該是1 ,2,4,3。然而,輸出是1,2,3,4並且全部在相同的線程中。然後我改變的代碼,與
val result = delayed.map{ message =>
println(new Date() + "-3-" + Thread.currentThread().getId)
Ok(message)
}
取代
val result = delayed.map{
println(new Date() + "-3-" + Thread.currentThread().getId)
Ok(_)
}
然後輸出爲1,2,4,3,和圖3是在不同的線程。
有人能告訴我原因嗎?謝謝!