diff options
author | Simon Rettberg | 2016-01-08 09:42:37 +0100 |
---|---|---|
committer | Simon Rettberg | 2016-01-08 09:42:37 +0100 |
commit | b16debb689473300191f0b5e8efbcd079fee2aae (patch) | |
tree | ebda9500b60af719d6896abcc223ef67fbe14698 | |
parent | [client] change checkbox for lecture location showing mode to radio buttons (diff) | |
download | tutor-module-b16debb689473300191f0b5e8efbcd079fee2aae.tar.gz tutor-module-b16debb689473300191f0b5e8efbcd079fee2aae.tar.xz tutor-module-b16debb689473300191f0b5e8efbcd079fee2aae.zip |
[server] Use GrowingThreadPoolExecutor everywhere
6 files changed, 40 insertions, 16 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java index 931b2f23..66062303 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java @@ -41,7 +41,7 @@ public class App { public static void main(String[] args) throws TTransportException, NoSuchAlgorithmException, IOException, KeyManagementException { //get going and show basic information in log file - BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%-5p [%t] %C{1} - %m%n"))); + BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d %-5p [%t] %C{1} - %m%n"))); if (args.length != 0 && args[0].equals("debug")) { DEBUG = true; } diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java index a8023989..45e299d1 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/FileServer.java @@ -10,7 +10,7 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLContext; @@ -21,6 +21,7 @@ import org.openslx.bwlp.sat.database.models.LocalImageVersion; import org.openslx.bwlp.sat.util.Constants; import org.openslx.bwlp.sat.util.FileSystem; import org.openslx.bwlp.sat.util.Formatter; +import org.openslx.bwlp.sat.util.GrowingThreadPoolExecutor; import org.openslx.bwlp.sat.util.Identity; import org.openslx.bwlp.sat.util.PrioThreadFactory; import org.openslx.bwlp.thrift.iface.ImageDetailsRead; @@ -42,7 +43,7 @@ public class FileServer implements IncomingEvent { private final Listener sslListener; - private final ThreadPoolExecutor transferPool = new ThreadPoolExecutor(1, Constants.MAX_UPLOADS + private final ExecutorService transferPool = new GrowingThreadPoolExecutor(1, Constants.MAX_UPLOADS + Constants.MAX_DOWNLOADS, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(1), new PrioThreadFactory("ClientTransferPool", Thread.NORM_PRIORITY - 2)); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java index 285380fc..7c6ea310 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/IncomingDataTransfer.java @@ -8,7 +8,7 @@ import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.SSLContext; @@ -163,7 +163,7 @@ public class IncomingDataTransfer extends AbstractTransfer implements HashCheckC * Called periodically if this is a transfer from the master server, so we * can make sure the transfer is running. */ - public void heartBeat(ThreadPoolExecutor pool) { + public void heartBeat(ExecutorService pool) { if (masterTransferInfo == null) return; synchronized (this) { @@ -221,14 +221,13 @@ public class IncomingDataTransfer extends AbstractTransfer implements HashCheckC } /** - * Add another connection for this file transfer. Currently only one - * connection is allowed, but this might change in the future. + * Add another connection for this file transfer. * * @param connection * @return true if the connection is accepted, false if it should be * discarded */ - public synchronized boolean addConnection(final Downloader connection, ThreadPoolExecutor pool) { + public synchronized boolean addConnection(final Downloader connection, ExecutorService pool) { if (state == TransferState.FINISHED || state == TransferState.ERROR) return false; synchronized (downloads) { diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/OutgoingDataTransfer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/OutgoingDataTransfer.java index 917611c7..31c219aa 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/OutgoingDataTransfer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/OutgoingDataTransfer.java @@ -3,7 +3,7 @@ package org.openslx.bwlp.sat.fileserv; import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.ExecutorService; import org.apache.log4j.Logger; import org.openslx.bwlp.sat.util.Constants; @@ -31,19 +31,18 @@ public class OutgoingDataTransfer extends AbstractTransfer { * Called periodically if this is a transfer from the master server, so we * can make sure the transfer is running. */ - public void heartBeat(ThreadPoolExecutor pool) { + public void heartBeat(ExecutorService pool) { // TODO } /** - * Add another connection for this file transfer. Currently only one - * connection is allowed, but this might change in the future. + * Add another connection for this file transfer. * * @param connection * @return true if the connection is accepted, false if it should be * discarded */ - public synchronized boolean addConnection(final Uploader connection, ThreadPoolExecutor pool) { + public synchronized boolean addConnection(final Uploader connection, ExecutorService pool) { if (isCanceled) return false; potentialFinishTime.set(0); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java index 29f47e05..f7a9de85 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/SyncTransferHandler.java @@ -6,13 +6,13 @@ import java.util.Iterator; import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.apache.log4j.Logger; import org.apache.thrift.TException; import org.openslx.bwlp.sat.util.Constants; import org.openslx.bwlp.sat.util.Formatter; +import org.openslx.bwlp.sat.util.GrowingThreadPoolExecutor; import org.openslx.bwlp.sat.util.PrioThreadFactory; import org.openslx.bwlp.thrift.iface.ImagePublishData; import org.openslx.bwlp.thrift.iface.InvocationError; @@ -31,7 +31,7 @@ public class SyncTransferHandler { private static final Logger LOGGER = Logger.getLogger(SyncTransferHandler.class); - private static final ThreadPoolExecutor transferPool = new ThreadPoolExecutor(1, + private static final GrowingThreadPoolExecutor transferPool = new GrowingThreadPoolExecutor(1, Constants.MAX_MASTER_UPLOADS + Constants.MAX_MASTER_DOWNLOADS, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(1), new PrioThreadFactory("MasterTransferPool", Thread.NORM_PRIORITY - 3)); diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/GrowingThreadPoolExecutor.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/GrowingThreadPoolExecutor.java index becccf2f..a7265199 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/GrowingThreadPoolExecutor.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/util/GrowingThreadPoolExecutor.java @@ -1,6 +1,9 @@ package org.openslx.bwlp.sat.util; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -11,10 +14,32 @@ import java.util.concurrent.TimeUnit; public class GrowingThreadPoolExecutor extends ThreadPoolExecutor { private int userSpecifiedCorePoolSize; private int taskCount; + + /** + * The default rejected execution handler + */ + private static final RejectedExecutionHandler defaultHandler = + new AbortPolicy(); public GrowingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { - super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); + this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, defaultHandler); + } + + public GrowingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, + BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) { + this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, defaultHandler); + } + + public GrowingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, + BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) { + this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), + handler); + } + + public GrowingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, + BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) { + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); userSpecifiedCorePoolSize = corePoolSize; } |