use of com.alipay.sofa.ark.common.thread.CommonThreadPool in project sofa-ark by sofastack.
the class StandardTelnetServerImpl method run.
@Override
public void run() {
AssertUtils.isTrue(port > 0, "Telnet port should be positive integer.");
try {
LOGGER.info("Listening on port: " + port);
CommonThreadPool workerPool = new CommonThreadPool().setCorePoolSize(WORKER_THREAD_POOL_SIZE).setDaemon(true).setThreadPoolName(Constants.TELNET_SERVER_WORKER_THREAD_POOL_NAME);
ThreadPoolManager.registerThreadPool(Constants.TELNET_SERVER_WORKER_THREAD_POOL_NAME, workerPool);
nettyTelnetServer = new NettyTelnetServer(port, workerPool.getExecutor());
nettyTelnetServer.open();
} catch (InterruptedException e) {
LOGGER.error("Unable to open netty telnet server.", e);
throw new ArkRuntimeException(e);
}
}
use of com.alipay.sofa.ark.common.thread.CommonThreadPool in project sofa-ark by alipay.
the class ClassLoaderConcurrencyTest method concurrencyLoadClass.
@Test
public void concurrencyLoadClass() {
final BizClassLoader bizClassLoader = new BizClassLoader("test:1.0", new URL[] { classPathURL });
final AtomicBoolean result = new AtomicBoolean(true);
int totalTimes = 100;
ThreadPoolExecutor executor = new CommonThreadPool().getExecutor();
final CountDownLatch countDownLatch = new CountDownLatch(totalTimes);
for (int index = 0; index < totalTimes; index++) {
if (result.get()) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
bizClassLoader.loadClass(ClassLoaderTestClass.class.getName(), true);
} catch (ClassNotFoundException e) {
// ingore
} catch (LinkageError e) {
result.set(false);
} finally {
countDownLatch.countDown();
}
}
});
} else {
countDownLatch.countDown();
}
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
// ignore
} finally {
executor.shutdown();
}
Assert.assertTrue("should not get linkega error when load class", result.get());
}
use of com.alipay.sofa.ark.common.thread.CommonThreadPool in project sofa-ark by alipay.
the class StandardTelnetServerImpl method run.
@Override
public void run() {
AssertUtils.isTrue(port > 0, "Telnet port should be positive integer.");
try {
LOGGER.info("Listening on port: " + port);
CommonThreadPool workerPool = new CommonThreadPool().setCorePoolSize(WORKER_THREAD_POOL_SIZE).setDaemon(true).setThreadPoolName(Constants.TELNET_SERVER_WORKER_THREAD_POOL_NAME);
ThreadPoolManager.registerThreadPool(Constants.TELNET_SERVER_WORKER_THREAD_POOL_NAME, workerPool);
nettyTelnetServer = new NettyTelnetServer(port, workerPool.getExecutor());
nettyTelnetServer.open();
} catch (InterruptedException e) {
LOGGER.error("Unable to open netty telnet server.", e);
throw new ArkRuntimeException(e);
}
}
use of com.alipay.sofa.ark.common.thread.CommonThreadPool in project sofa-ark by alipay.
the class ArkCommandHandler method init.
private static void init() {
CommonThreadPool commandPool = new CommonThreadPool().setAllowCoreThreadTimeOut(true).setThreadPoolName(Constants.TELNET_COMMAND_THREAD_POOL_NAME).setDaemon(true);
ThreadPoolManager.registerThreadPool(Constants.TELNET_COMMAND_THREAD_POOL_NAME, commandPool);
}
use of com.alipay.sofa.ark.common.thread.CommonThreadPool in project sofa-ark by sofastack.
the class ClassLoaderConcurrencyTest method concurrencyLoadClass.
@Test
public void concurrencyLoadClass() {
final BizClassLoader bizClassLoader = new BizClassLoader("test:1.0", new URL[] { classPathURL });
final AtomicBoolean result = new AtomicBoolean(true);
int totalTimes = 100;
ThreadPoolExecutor executor = new CommonThreadPool().getExecutor();
final CountDownLatch countDownLatch = new CountDownLatch(totalTimes);
for (int index = 0; index < totalTimes; index++) {
if (result.get()) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
bizClassLoader.loadClass(ClassLoaderTestClass.class.getName(), true);
} catch (ClassNotFoundException e) {
// ingore
} catch (LinkageError e) {
result.set(false);
} finally {
countDownLatch.countDown();
}
}
});
} else {
countDownLatch.countDown();
}
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
// ignore
} finally {
executor.shutdown();
}
Assert.assertTrue("should not get linkega error when load class", result.get());
}
Aggregations