Enhance ExecutorUtil to create ScheduledThreadPool (#29)

This commit is contained in:
Linary 2019-06-24 15:18:21 +08:00 committed by Jermy Li
parent 48a39fcef8
commit 85a6b7e24d
5 changed files with 24 additions and 6 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-common</artifactId>
<version>1.6.5</version>
<version>1.6.6</version>
<name>hugegraph-common</name>
<url>https://github.com/hugegraph/hugegraph-common</url>
@ -212,7 +212,7 @@
<manifestEntries>
<!-- Must be on one line, otherwise the automatic
upgrade script cannot replace the version number -->
<Implementation-Version>1.6.5.0</Implementation-Version>
<Implementation-Version>1.6.6.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>

View File

@ -24,7 +24,6 @@ import static org.glassfish.jersey.apache.connector.ApacheClientProperties.CONNE
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -50,6 +49,7 @@ import org.glassfish.jersey.internal.util.collection.Refs;
import org.glassfish.jersey.message.GZipEncoder;
import org.glassfish.jersey.uri.UriComponent;
import com.baidu.hugegraph.util.ExecutorUtil;
import com.google.common.collect.ImmutableMap;
public abstract class RestClient {
@ -98,7 +98,8 @@ public abstract class RestClient {
this.pool = (PoolingHttpClientConnectionManager)
config.getProperty(CONNECTION_MANAGER);
if (this.pool != null) {
this.cleanExecutor = Executors.newScheduledThreadPool(1);
this.cleanExecutor = ExecutorUtil.newScheduledThreadPool(
"conn-clean-worker-%d");
this.cleanExecutor.scheduleWithFixedDelay(() -> {
PoolStats stats = this.pool.getTotalStats();
int using = stats.getLeased() + stats.getPending();

View File

@ -77,7 +77,7 @@ public class RestResult {
JavaType type = mapper.getTypeFactory()
.constructParametrizedType(ArrayList.class,
List.class, clazz);
return mapper.readValue(element.toString(), type);
return mapper.convertValue(element, type);
} catch (IOException e) {
throw new SerializeException(
"Failed to deserialize %s", e, this.content);

View File

@ -21,16 +21,33 @@ package com.baidu.hugegraph.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;
public final class ExecutorUtil {
public static ExecutorService newFixedThreadPool(String name) {
return newFixedThreadPool(1, name);
}
public static ExecutorService newFixedThreadPool(int size, String name) {
ThreadFactory factory = new BasicThreadFactory.Builder()
.namingPattern(name)
.build();
return Executors.newFixedThreadPool(size, factory);
}
public static ScheduledExecutorService newScheduledThreadPool(String name) {
return newScheduledThreadPool(1, name);
}
public static ScheduledExecutorService newScheduledThreadPool(int size,
String name) {
ThreadFactory factory = new BasicThreadFactory.Builder()
.namingPattern(name)
.build();
return Executors.newScheduledThreadPool(size, factory);
}
}

View File

@ -27,5 +27,5 @@ public class CommonVersion {
// The second parameter of Version.of() is for all-in-one JAR
public static final Version VERSION = Version.of(CommonVersion.class,
"1.6.5");
"1.6.6");
}