本文整理匯總了Java中java.nio.channels.AsynchronousChannelGroup.withFixedThreadPool方法的典型用法代碼示例。如果您正苦於以下問題:Java AsynchronousChannelGroup.withFixedThreadPool方法的具體用法?Java AsynchronousChannelGroup.withFixedThreadPool怎麽用?Java AsynchronousChannelGroup.withFixedThreadPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.channels.AsynchronousChannelGroup
的用法示例。
在下文中一共展示了AsynchronousChannelGroup.withFixedThreadPool方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: listen
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
@Override
public void listen(int thread, int port, AioServerListener listener) {
this.port = port;
this.listener = listener;
try {
channelGroup = AsynchronousChannelGroup.withFixedThreadPool(thread, Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverSocketChannel.bind(new InetSocketAddress(port));
serverSocketChannel.accept(null, this);
if (logger.isInfoEnable())
logger.info("啟動AIO監聽[{}]服務。", port);
} catch (IOException e) {
logger.warn(e, "啟動AIO監聽[{}]服務時發生異常!", port);
}
}
示例2: run
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
@Override
public void run() {
try {
final int workerThreads = Math.max(4, 2 *
Runtime.getRuntime().availableProcessors());
channelGroup = AsynchronousChannelGroup.withFixedThreadPool(
workerThreads, Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
serverSocketChannel.bind(new InetSocketAddress(port));
serverSocketChannel.accept(null,
new AcceptCompletionHandler(serverSocketChannel));
channelGroup.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
} catch(IOException | InterruptedException ex) {
Log.get().log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
示例3: main
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// create channel groups
ThreadFactory factory = new PrivilegedThreadFactory();
AsynchronousChannelGroup group1 = AsynchronousChannelGroup
.withFixedThreadPool(5, factory);
AsynchronousChannelGroup group2 = AsynchronousChannelGroup
.withCachedThreadPool(Executors.newCachedThreadPool(factory), 0);
AsynchronousChannelGroup group3 = AsynchronousChannelGroup
.withThreadPool(Executors.newFixedThreadPool(10, factory));
try {
// execute simple tasks
testSimpleTask(group1);
testSimpleTask(group2);
testSimpleTask(group3);
// install security manager and test again
System.setSecurityManager( new SecurityManager() );
testSimpleTask(group1);
testSimpleTask(group2);
testSimpleTask(group3);
// attempt to execute tasks that run with only frames from boot
// class loader on the stack.
testAttackingTask(group1);
testAttackingTask(group2);
testAttackingTask(group3);
} finally {
group1.shutdown();
group2.shutdown();
group3.shutdown();
}
}
示例4: main
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// create channel groups
ThreadFactory factory = new PrivilegedThreadFactory();
AsynchronousChannelGroup group1 = AsynchronousChannelGroup
.withFixedThreadPool(5, factory);
AsynchronousChannelGroup group2 = AsynchronousChannelGroup
.withCachedThreadPool(Executors.newCachedThreadPool(factory), 0);
try {
// execute simple tasks
testSimpleTask(group1);
testSimpleTask(group2);
// install security manager and test again
System.setSecurityManager( new SecurityManager() );
testSimpleTask(group1);
testSimpleTask(group2);
// attempt to execute tasks that run with only frames from boot
// class loader on the stack.
testAttackingTask(group1);
testAttackingTask(group2);
} finally {
group1.shutdown();
group2.shutdown();
}
}
示例5: setUpHandlers
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public void setUpHandlers() {
try {
AsynchronousChannelGroup asyncChannelGroup = AsynchronousChannelGroup.withFixedThreadPool(poolSize, Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel.open(asyncChannelGroup).bind(new InetSocketAddress(listenPort));
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
log.info("** " + poolSize + " handler thread has been setup! **");
log.info("** Socket Server has been startup, listen port is " + listenPort + "! **");
} catch (IOException e) {
log.error("setUpHandlers error: ", e);
}
}
示例6: setUpHandlers
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public void setUpHandlers() {
try {
AsynchronousChannelGroup asyncChannelGroup = AsynchronousChannelGroup.withFixedThreadPool(poolSize, Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel.open(asyncChannelGroup).bind(new InetSocketAddress(listenPort));
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
} catch (IOException e) {
e.printStackTrace();
}
log.info("** " + poolSize + " handler thread has been setup! **");
log.info("** Socket Server has been startup, listen port is " + listenPort + "! **");
}
示例7: setUpHandlers
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public void setUpHandlers() {
try {
AsynchronousChannelGroup asyncChannelGroup = AsynchronousChannelGroup
.withFixedThreadPool(poolSize,Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel
.open(asyncChannelGroup).bind(new InetSocketAddress(listenPort));
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
//serverSocketChannel.setOption(StandardSocketOption.TCP_NODELAY, true);
} catch (IOException e) {
e.printStackTrace();
}
log.info("** " + poolSize + " handler thread has been setup! **");
log.info("** Socket Server has been startup, listen port is " + listenPort + "! **");
}