Created
January 8, 2015 13:40
-
-
Save a-hisame/d6c1b19079d8a2fd42c8 to your computer and use it in GitHub Desktop.
実行するとMainスレッドが落ちても裏でスレッドが動作しててアプリケーションが終了しない。
This file contains hidden or 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
import dispatch.url | |
import dispatch.Http | |
import dispatch.as | |
import dispatch.Defaults._ | |
object Main { | |
def main(args: Array[String]): Unit = { | |
import dispatch._, Defaults._ | |
val svc = url("http://www.google.co.jp/") | |
for { | |
response <- Http(svc OK as.String) | |
} { | |
println(response) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ubuntuでも同様の現象を確認。
原因は、Http(Singleton)オブジェクトが所有するclientが閉じられないため。
末尾に Http.shutdown() を実行するとアプリケーションは終了するようになるが、今度は再度Httpオブジェクトが使えなくなってしまう。
解決策としては、Httpオブジェクトを自分で作ってクローズすればよい。