本文整理匯總了Java中java.nio.channels.AsynchronousChannelGroup.withThreadPool方法的典型用法代碼示例。如果您正苦於以下問題:Java AsynchronousChannelGroup.withThreadPool方法的具體用法?Java AsynchronousChannelGroup.withThreadPool怎麽用?Java AsynchronousChannelGroup.withThreadPool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.channels.AsynchronousChannelGroup
的用法示例。
在下文中一共展示了AsynchronousChannelGroup.withThreadPool方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: AioServer
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
/**
* init the aioServer
*
* @param port
* @param channelWorkers
* @throws IOException
*/
public AioServer(int port, ExecutorService channelWorkers , AioDataDealerFactory aioDataDealerFactory) throws IOException {
this.aioDataDealerFactory = aioDataDealerFactory;
channelGroup = AsynchronousChannelGroup.withThreadPool(channelWorkers);
this.port = port;
listener = createListener(channelGroup);
acceptHandler = new AcceptHandler();
}
示例3: start
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public void start(String serverIp, int serverPort) throws IOException
{
this.serverNode = new Node(serverIp, serverPort);
ExecutorService groupExecutor = serverGroupContext.getGroupExecutor();
AsynchronousChannelGroup channelGroup = AsynchronousChannelGroup.withThreadPool(groupExecutor);
serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 64 * 1024);
InetSocketAddress listenAddress = null;
if (StringUtils.isBlank(serverIp))
{
listenAddress = new InetSocketAddress(serverPort);
} else
{
listenAddress = new InetSocketAddress(serverIp, serverPort);
}
serverSocketChannel.bind(listenAddress, 0);
AcceptCompletionHandler<SessionContext, P, R> acceptCompletionHandler = serverGroupContext.getAcceptCompletionHandler();
serverSocketChannel.accept(this, acceptCompletionHandler);
System.out.println("start server on " + this.serverNode);
}
示例4: init
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
@Setup
public void init() throws IOException {
System.out.println("Setup");
monitor.set(0);
if (executorService == null) {
executorService = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build());
}
if (asynChanGroupFibers == null) {
asynChanGroupFibers = AsynchronousChannelGroup.withThreadPool((ExecutorService) DefaultFiberScheduler.getInstance().getExecutor());
}
if (asynChanGroupFJP == null) {
asynChanGroupFJP = AsynchronousChannelGroup.withThreadPool(ForkJoinPool.commonPool());
}
}
示例5: MycatServer
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public MycatServer() {
this.config = new MycatConfig();
SystemConfig system = config.getSystem();
int processorCount = system.getProcessors();
asyncChannelGroups = new AsynchronousChannelGroup[processorCount];
// startup processors
int threadpool = system.getProcessorExecutor();
try {
aioExecutor = ExecutorUtil.create("AIOExecutor", threadpool);
processors = new NIOProcessor[processorCount];
int processBuferPool = system.getProcessorBufferPool();
int processBufferChunk = system.getProcessorBufferChunk();
for (int i = 0; i < processors.length; i++) {
asyncChannelGroups[i] = AsynchronousChannelGroup
.withThreadPool(aioExecutor);
processors[i] = new NIOProcessor("Processor" + i,
processBuferPool, processBufferChunk, aioExecutor);
}
// startup connector
connector = new NIOConnector();
connector.setWriteQueueCapcity(system.getFrontWriteQueueSize());
connector.setProcessors(processors);
} catch (IOException e) {
throw new RuntimeException(e);
}
this.timer = new Timer(NAME + "Timer", true);
this.timerExecutor = ExecutorUtil.create("TimerExecutor",
system.getTimerExecutor());
this.sqlRecorder = new SQLRecorder(system.getSqlRecordCount());
this.isOnline = new AtomicBoolean(true);
cacheService = new CacheService();
routerService = new RouteService(cacheService);
// load datanode active index from properties
dnIndexProperties = loadDnIndexProps();
this.startupTime = TimeUtil.currentTimeMillis();
}
示例6: AbstractServer
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
/**
* @param local The socket address that the server is bound to
* @throws IOException when failing to start the server
*/
protected AbstractServer(SocketAddress local) throws IOException {
this.executor = Executors.newCachedThreadPool();
this.channelGroup = AsynchronousChannelGroup.withThreadPool(executor);
this.listener = AsynchronousServerSocketChannel
.open(channelGroup)
.setOption(StandardSocketOptions.SO_REUSEADDR, true)
.bind(local);
this.run();
this.listening();
}
示例7: IRCClient
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
/**
* Constructs a new
* <code>IRCClient</code> with the specified nickname, username, real name,
* invisibility flag and
* <code>IRCAdapter</code>. A call to
* <code>connect()</code> must be made in order to resolve and connect this
* <code>IRCClient</code>.
*
* @param nickname the nickname.
* @param username the username.
* @param realname the real name.
* @param invisible whether the client should be invisible to other clients.
* @param adapter the adapter to be associated with this
* <code>IRCClient</code>.
*
* @exception IOException if an I/O error occurs when creating the
* connection.
*/
public IRCClient(String nickname, String username, String realname, boolean invisible, IRCAdapter adapter) throws IOException {
Objects.requireNonNull(nickname);
Objects.requireNonNull(username);
Objects.requireNonNull(realname);
Objects.requireNonNull(adapter);
if (nickname.contains(" ")) {
throw new IllegalArgumentException("Nickname must not contain spaces");
}
if (username.contains(" ")) {
throw new IllegalArgumentException("Username must not contain spaces");
}
if (nickname.length() > 16) {
throw new IllegalArgumentException("Nickname must be no more than 16 characters");
}
this.group = AsynchronousChannelGroup.withThreadPool(Executors.newFixedThreadPool(1));
this.socket = AsynchronousSocketChannel.open(group);
this.nickname = nickname;
this.password = Long.toString(random.nextLong(), 36);
this.username = username;
this.realname = realname;
this.invisible = invisible;
this.adapter = adapter;
}
示例8: PoolManager
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public PoolManager(Protocol protocol, int thread_pool_queue_size) throws GeneralSecurityException, IOException {
this.protocol = protocol;
if (protocol == null) {
throw new NullPointerException("\"protocol\" can't to be null");
}
if (thread_pool_queue_size < 1) {
throw new IOException("Can't set thread_pool_queue_size to " + thread_pool_queue_size);
}
local_servers = new ArrayList<>();
executor = new ThreadPoolExecutorFactory("PoolManager", Thread.MAX_PRIORITY - 1, thread_pool_queue_size);
channel_group = AsynchronousChannelGroup.withThreadPool(executor.getThreadPoolExecutor());
pressure_measurement_sended = new PressureMeasurement();
pressure_measurement_recevied = new PressureMeasurement();
pressure_measurement_netdiscover = new PressureMeasurement();
nodes = Collections.synchronizedList(new ArrayList<>());
onRemoveNodeCallbackList = Collections.synchronizedList(new ArrayList<>());
autodiscover_can_be_remake = new AtomicBoolean(true);
uuid_ref = UUID.randomUUID();
addr_master = new AddressMaster();
shutdown_hook = new ShutdownHook();
all_request_handlers = new AllRequestHandlers(this);
pool_scheduler = new ActivityScheduler<>();
pool_scheduler.add(this, getScheduledAction());
node_scheduler = new ActivityScheduler<>();
}
示例9: AioClient
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public AioClient(ExecutorService channelWorkers, AioDataDealerFactory aioDataDealerFactory) throws IOException {
// ExecutorService channelWorkers = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), Executors.defaultThreadFactory());
channelGroup = AsynchronousChannelGroup.withThreadPool(channelWorkers);
this.aioDataDealerFactory = aioDataDealerFactory;
}
示例10: createAsynchronousChannelGroup
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public AsynchronousChannelGroup createAsynchronousChannelGroup() throws IOException {
return AsynchronousChannelGroup.withThreadPool(executor);
}
示例11: ClamAVAsync
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
public ClamAVAsync(InetSocketAddress address, int timeout) throws IOException {
this.asynchronousChannelGroup = AsynchronousChannelGroup.withThreadPool(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()));
this.address = address;
this.timeout = timeout;
}
示例12: AioClient
import java.nio.channels.AsynchronousChannelGroup; //導入方法依賴的package包/類
/**
* @param serverIp 可以為空
* @param serverPort
* @param aioDecoder
* @param aioEncoder
* @param aioHandler
*
* @author: tanyaowu
* @throws IOException
* @創建時間: 2016年11月15日 下午1:09:28
*
*/
public AioClient(final ClientGroupContext<SessionContext, P, R> clientGroupContext) throws IOException
{
super();
this.clientGroupContext = clientGroupContext;
ExecutorService groupExecutor = clientGroupContext.getGroupExecutor();
this.channelGroup = AsynchronousChannelGroup.withThreadPool(groupExecutor);
startHeartbeatTask();
startReconnTask();
}