當前位置: 首頁>>代碼示例>>Java>>正文


Java AsynchronousChannelGroup.withFixedThreadPool方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:heisedebaise,項目名稱:tephra,代碼行數:18,代碼來源:AioServerImpl.java

示例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);
    }
}
 
開發者ID:cli,項目名稱:sonews,代碼行數:20,代碼來源:AsynchronousNNTPDaemon.java

示例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();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:34,代碼來源:AsExecutor.java

示例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();
    }
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:28,代碼來源:AsExecutor.java

示例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);
	}
}
 
開發者ID:zijan,項目名稱:Tatala-RPC,代碼行數:13,代碼來源:AioSocketServer.java

示例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 + "! **");
}
 
開發者ID:zijan,項目名稱:Tatala-RPC,代碼行數:12,代碼來源:AioSocketServer.java

示例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 + "! **");
}
 
開發者ID:zijan,項目名稱:Tatala-RPC,代碼行數:16,代碼來源:AioSocketServer.java


注:本文中的java.nio.channels.AsynchronousChannelGroup.withFixedThreadPool方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。