Reformat and clean up "server" package
This commit is contained in:
@@ -22,20 +22,19 @@ package server;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ronan
|
||||
*/
|
||||
public class ThreadManager {
|
||||
private static ThreadManager instance = new ThreadManager();
|
||||
|
||||
private static final ThreadManager instance = new ThreadManager();
|
||||
|
||||
public static ThreadManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private ThreadPoolExecutor tpe;
|
||||
|
||||
|
||||
private ThreadManager() {}
|
||||
|
||||
|
||||
private class RejectedExecutionHandlerImpl implements RejectedExecutionHandler {
|
||||
|
||||
@Override
|
||||
@@ -45,23 +44,24 @@ public class ThreadManager {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void newTask(Runnable r) {
|
||||
tpe.execute(r);
|
||||
}
|
||||
|
||||
|
||||
public void start() {
|
||||
RejectedExecutionHandler reh = new RejectedExecutionHandlerImpl();
|
||||
ThreadFactory tf = Executors.defaultThreadFactory();
|
||||
|
||||
|
||||
tpe = new ThreadPoolExecutor(20, 1000, 77, TimeUnit.SECONDS, new ArrayBlockingQueue<>(50), tf, reh);
|
||||
}
|
||||
|
||||
|
||||
public void stop() {
|
||||
tpe.shutdown();
|
||||
try {
|
||||
tpe.awaitTermination(5, TimeUnit.MINUTES);
|
||||
} catch (InterruptedException ie) {}
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user