Search in sources :

Example 1 with CommonThreadPool

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);
    }
}
Also used : CommonThreadPool(com.alipay.sofa.ark.common.thread.CommonThreadPool) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 2 with CommonThreadPool

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CommonThreadPool(com.alipay.sofa.ark.common.thread.CommonThreadPool) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Example 3 with CommonThreadPool

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);
    }
}
Also used : CommonThreadPool(com.alipay.sofa.ark.common.thread.CommonThreadPool) ArkRuntimeException(com.alipay.sofa.ark.exception.ArkRuntimeException)

Example 4 with CommonThreadPool

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);
}
Also used : CommonThreadPool(com.alipay.sofa.ark.common.thread.CommonThreadPool)

Example 5 with CommonThreadPool

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CommonThreadPool(com.alipay.sofa.ark.common.thread.CommonThreadPool) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) BaseTest(com.alipay.sofa.ark.container.BaseTest) Test(org.junit.Test)

Aggregations

CommonThreadPool (com.alipay.sofa.ark.common.thread.CommonThreadPool)6 BaseTest (com.alipay.sofa.ark.container.BaseTest)2 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Test (org.junit.Test)2