com.github.blackshadowwalker.spring.distributelock.redis.RedisLockExecutorService Maven / Gradle / Ivy
package com.github.blackshadowwalker.spring.distributelock.redis;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Created by ASUS on 2016/8/16.
*/
public class RedisLockExecutorService implements ExecutorService {
private ExecutorService service;
String prefix = "LOCK_";
static AtomicInteger lockIncr = new AtomicInteger(0);
public RedisLockExecutorService() {
service = Executors.newFixedThreadPool(20, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
if (r instanceof LockRunnable) {
thread.setUncaughtExceptionHandler(((LockRunnable) r).getHandler());
thread.setName(prefix + ((LockRunnable) r).getLockName());
} else {
thread.setName(prefix + lockIncr.incrementAndGet());
}
return thread;
}
});
}
@Override
public void shutdown() {
service.shutdown();
}
@Override
public List shutdownNow() {
return service.shutdownNow();
}
@Override
public boolean isShutdown() {
return service.isShutdown();
}
@Override
public boolean isTerminated() {
return service.isTerminated();
}
@Override
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
return service.awaitTermination(timeout, unit);
}
@Override
public Future submit(Callable task) {
return service.submit(task);
}
@Override
public Future submit(Runnable task, T result) {
return service.submit(task, result);
}
@Override
public Future> submit(Runnable task) {
return service.submit(task);
}
@Override
public List> invokeAll(Collection extends Callable> tasks) throws InterruptedException {
return service.invokeAll(tasks);
}
@Override
public List> invokeAll(Collection extends Callable> tasks, long timeout, TimeUnit unit) throws InterruptedException {
return service.invokeAll(tasks, timeout, unit);
}
@Override
public T invokeAny(Collection extends Callable> tasks) throws InterruptedException, ExecutionException {
return service.invokeAny(tasks);
}
@Override
public T invokeAny(Collection extends Callable> tasks, long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return service.invokeAny(tasks, timeout, unit);
}
@Override
public void execute(Runnable command) {
service.execute(command);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy