Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nacos fails to start when the cpu core is less than 2 #130

Closed
wyp12 opened this issue Oct 17, 2018 · 0 comments
Closed

Nacos fails to start when the cpu core is less than 2 #130

wyp12 opened this issue Oct 17, 2018 · 0 comments
Assignees

Comments

@wyp12
Copy link
Collaborator

wyp12 commented Oct 17, 2018

Nacos fails to start when the cpu core is less than 2,Exception appear when start:

java.lang.ExceptionInInitializerError: null
        at com.alibaba.nacos.naming.healthcheck.AbstractHealthCheckProcessor.<clinit>(AbstractHealthCheckProcessor.java:148)
        at com.alibaba.nacos.naming.healthcheck.HealthCheckTask.run(HealthCheckTask.java:61)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:756)
Caused by: java.lang.IllegalArgumentException: null
        at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1307)
        at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1230)
        at java.util.concurrent.Executors.newFixedThreadPool(Executors.java:151)
        at com.alibaba.nacos.naming.healthcheck.MysqlHealthCheckProcessor.<clinit>(MysqlHealthCheckProcessor.java:52)
        ... 9 common frames omitted

Reason:

    private static final ScheduledExecutorService EXECUTOR = Executors
            .newScheduledThreadPool(Runtime.getRuntime().availableProcessors() / 2, new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread thread = new Thread(r);
                    thread.setDaemon(true);
                    thread.setName("com.alibaba.nacos.naming.health");
                    return thread;
                }
            });

Runtime.getRuntime().availableProcessors() / 2 value is 0, when invoker ThreadPoolExecutor(),
throw new IllegalArgumentException();

  public ThreadPoolExecutor(int corePoolSize,
                              int maximumPoolSize,
                              long keepAliveTime,
                              TimeUnit unit,
                              BlockingQueue<Runnable> workQueue,
                              ThreadFactory threadFactory,
                              RejectedExecutionHandler handler) {
        if (corePoolSize < 0 ||
            maximumPoolSize <= 0 ||
            maximumPoolSize < corePoolSize ||
            keepAliveTime < 0)
            throw new IllegalArgumentException();
        if (workQueue == null || threadFactory == null || handler == null)
            throw new NullPointerException();
        this.corePoolSize = corePoolSize;
        this.maximumPoolSize = maximumPoolSize;
        this.workQueue = workQueue;
        this.keepAliveTime = unit.toNanos(keepAliveTime);
        this.threadFactory = threadFactory;
        this.handler = handler;
    }
@wyp12 wyp12 self-assigned this Oct 17, 2018
@nkorange nkorange self-assigned this Oct 17, 2018
@nkorange nkorange added the bug label Oct 17, 2018
@nkorange nkorange mentioned this issue Oct 19, 2018
5 tasks
realJackSun pushed a commit to realJackSun/nacos that referenced this issue Mar 31, 2021
Co-authored-by: wangchunhao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants