Skip to content

Commit

Permalink
add api for setting thread pool name
Browse files Browse the repository at this point in the history
Change-Id: I93aeddc6783e6b03d2aa31aa8ca42059e253ba81
  • Loading branch information
javeme committed Oct 19, 2018
1 parent 904f426 commit 7ffaa97
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-common</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>

<name>hugegraph-common</name>
<url>https://github.com/hugegraph/hugegraph-common</url>
Expand Down Expand Up @@ -192,7 +192,7 @@
<manifestEntries>
<!-- Must be on one line, otherwise the automatic
upgrade script cannot replace the version number -->
<Implementation-Version>1.5.2.0</Implementation-Version>
<Implementation-Version>1.5.3.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/baidu/hugegraph/event/EventHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

Expand All @@ -36,13 +35,15 @@

import com.baidu.hugegraph.iterator.ExtendableIterator;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.ExecutorUtil;
import com.baidu.hugegraph.util.Log;
import com.google.common.collect.ImmutableList;

public class EventHub {

private static final Logger LOG = Log.logger(EventHub.class);

public static final String EVENT_WORKER = "event-worker-%d";
public static final String ANY_EVENT = "*";

private static final List<EventListener> EMPTY = ImmutableList.of();
Expand Down Expand Up @@ -70,7 +71,7 @@ public static synchronized void init(int poolSize) {
return;
}
LOG.debug("Init pool(size {}) for EventHub", poolSize);
executor = Executors.newFixedThreadPool(poolSize);
executor = ExecutorUtil.newFixedThreadPool(poolSize, EVENT_WORKER);
}

public static synchronized boolean destroy(long timeout)
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/baidu/hugegraph/util/ExecutorUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2017 HugeGraph Authors
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.baidu.hugegraph.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;

public final class ExecutorUtil {

public static ExecutorService newFixedThreadPool(int size, String name) {
ThreadFactory factory = new BasicThreadFactory.Builder()
.namingPattern(name)
.build();
return java.util.concurrent.Executors.newFixedThreadPool(size, factory);
}
}

0 comments on commit 7ffaa97

Please sign in to comment.