2016-06-18 119 views
1

我在scala編程使用play framework 2.5.3開發一個web應用程序,我需要創建一個TCP服務器/客戶端,它將利用播放的異步模型。讀了一下之後。 我在Java 7中瞭解到NIO.2'sAsynchronousServerSocketChannel/AsynchronousSocketChannel,我發現NIO.2的實施斯卡拉在Github這裏(https://gist.github.com/happy4crazy/1901b1be0cb924898d13)。斯卡拉播放框架和NIO.2

修改它之後,我能夠在jvisualvm運行代碼並檢查線程。我注意到NIO.2在接受連接時創建了它自己的Thread。我擔心NIO.2's Threadsplay framework's調度程序線程會引起問題和減緩時在高應力下的Web應用程序。可這導致的問題,有沒有更好的方式來integrate NIO.2與遊戲框架的異步模式?

請多關照 弗朗西斯

回答

0

當播放一個Netty的I/O,Netty的都有自己的線程池,它並不會造成問題(https://www.playframework.com/documentation/2.5.x/ThreadPools)。所以我可以假設NIO.2擁有自己的線程池也是安全的。

同時,您可以配置NIO.2使用相同的線程池的播放。首先,提取Play的線程池。讓它被命名爲executor。然後

AsynchronousChannelGroup group = AsynchronousChannelGroup.withThreadPool(executor); 
AsynchronousServerSocketChannel channel = AsynchronousServerSocketChannel.open(group); 
AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(group);