为elasticsearch threadPool获取OutOfMemoryError

时间:2014-12-26 13:00:33

标签: java spring-mvc elasticsearch

我使用以下代码从ES服务器获取传输客户端。现在万一服务器出现故障我在tomcat中出现OutOfMemoryError错误,因为弹出搜索线程池没有被释放。请让我知道如何处理ES线程池。

public static Client getInstance() {
    String ipAddress = MessageTranslator.getMessage("es.cluster.ip");
    int transportClientPort = 0;
    String clusterName = MessageTranslator.getMessage("es.cluster.name");

    try {
        transportClientPort =
            Integer.parseInt(MessageTranslator
                .getMessage("es.transportclient.port"));
    }
    catch (Exception e) {
        transportClientPort = 9300;
        LogImpl.setWarning(ESClientFactory.class, e);
    }

    logger.debug("got the client ip as :" + ipAddress + " and port :"
        + transportClientPort);
    if (instance == null) {
        logger
            .debug("the client instance is null, creating a new instance");
        ImmutableSettings.Builder settings =
            ImmutableSettings.settingsBuilder();
        settings.put("cluster.name", clusterName);
        settings.build();
        instance =
            new TransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(
                    ipAddress, transportClientPort));

        logger.debug("returning the new created client instance...");
        return instance;
    }
    logger
        .debug("returning the existing transport client object connection.");
    return instance;
}

获取以下异常。

56 errors] with root cause org.elasticsearch.common.inject.CreationException: Guice creation errors:

Error injecting constructor, java.lang.OutOfMemoryError: unable to create new native thread   
    at org.elasticsearch.threadpool.ThreadPool.<init>(Unknown Source)   while locating org.elasticsearch.threadpool.ThreadPool 
Caused by: java.lang.OutOfMemoryError: unable to create new native thread   at java.lang.Thread.start0(Native Method)   
    at java.lang.Thread.start(Thread.java:640)  
    at org.elasticsearch.threadpool.ThreadPool.<init>(ThreadPool.java:141) 
    at sun.reflect.GeneratedConstructorAccessor216.newInstance(Unknown Source)  
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)  
    at org.elasticsearch.common.inject.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:54)   
    at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:86)
    at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:98)
    at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) 
    at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:837)
    at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) 
    at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:57)
    at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:45) 
    at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:200)
    at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:193)

0 个答案:

没有答案