diff options
author | Simon Rettberg | 2023-02-15 15:01:53 +0100 |
---|---|---|
committer | Simon Rettberg | 2023-02-15 15:01:53 +0100 |
commit | 96f761912019bcf6b52e8b2e2f4cf4a7ffe5ab17 (patch) | |
tree | face49df473d58b2c761535d6ac055ce03372ec6 /src/main/java/org/openslx/taskmanager | |
parent | [WakeOnLan] Fix thread leak from ThreadPool (diff) | |
download | tmlite-bwlp-96f761912019bcf6b52e8b2e2f4cf4a7ffe5ab17.tar.gz tmlite-bwlp-96f761912019bcf6b52e8b2e2f4cf4a7ffe5ab17.tar.xz tmlite-bwlp-96f761912019bcf6b52e8b2e2f4cf4a7ffe5ab17.zip |
Add names to all ThreadPool threads
Diffstat (limited to 'src/main/java/org/openslx/taskmanager')
5 files changed, 17 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/DownloadFiles.java b/src/main/java/org/openslx/taskmanager/tasks/DownloadFiles.java index be3569d..ae67ec8 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/DownloadFiles.java +++ b/src/main/java/org/openslx/taskmanager/tasks/DownloadFiles.java @@ -26,6 +26,7 @@ import org.apache.commons.io.FilenameUtils; import org.openslx.satserver.util.Exec; import org.openslx.satserver.util.Util; import org.openslx.taskmanager.api.AbstractTask; +import org.openslx.util.PrioThreadFactory; import com.google.gson.annotations.Expose; @@ -120,7 +121,8 @@ public class DownloadFiles extends AbstractTask } final Path tmpDir = td; - ExecutorService tp = Executors.newFixedThreadPool( files.length > 3 ? 3 : files.length ); + ExecutorService tp = Executors.newFixedThreadPool( files.length > 3 ? 3 : files.length, + new PrioThreadFactory( "DL" ) ); final AtomicBoolean retval = new AtomicBoolean( true ); for ( final Task t : this.files ) { final FileStatus status = new FileStatus(); diff --git a/src/main/java/org/openslx/taskmanager/tasks/PortScan.java b/src/main/java/org/openslx/taskmanager/tasks/PortScan.java index 3471897..dab97f8 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/PortScan.java +++ b/src/main/java/org/openslx/taskmanager/tasks/PortScan.java @@ -19,6 +19,7 @@ import java.util.regex.Pattern; import org.apache.commons.io.FileUtils; import org.openslx.satserver.util.Exec; import org.openslx.taskmanager.api.AbstractTask; +import org.openslx.util.PrioThreadFactory; import com.google.gson.annotations.Expose; @@ -72,7 +73,8 @@ public class PortScan extends AbstractTask certFile = tmpFile.getAbsolutePath(); } // Execute scan in parallel (4 tasks) to speed things up - ExecutorService tp = Executors.newFixedThreadPool( ports.length > 4 ? 4 : ports.length ); + ExecutorService tp = Executors.newFixedThreadPool( ports.length > 4 ? 4 : ports.length, + new PrioThreadFactory( "PortScan" ) ); final List<Result> results = new ArrayList<>(); for ( final int port : ports ) { tp.submit( new Callable<Object>() { @@ -90,7 +92,7 @@ public class PortScan extends AbstractTask } tp.shutdown(); try { - tp.awaitTermination( ports.length * 2, TimeUnit.SECONDS ); + tp.awaitTermination( ports.length * 2 + 10, TimeUnit.SECONDS ); } catch ( InterruptedException e ) { // ... } diff --git a/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java b/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java index cc7631d..b60b990 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java +++ b/src/main/java/org/openslx/taskmanager/tasks/RemoteExec.java @@ -18,6 +18,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.openslx.satserver.util.Util; import org.openslx.taskmanager.api.AbstractTask; +import org.openslx.util.PrioThreadFactory; import com.google.gson.annotations.Expose; import com.jcraft.jsch.ChannelExec; @@ -117,7 +118,8 @@ public class RemoteExec extends AbstractTask @Override protected boolean execute() { - ExecutorService tp = Executors.newFixedThreadPool( clients.length > 4 ? 4 : clients.length ); + ExecutorService tp = Executors.newFixedThreadPool( clients.length > 4 ? 4 : clients.length, + new PrioThreadFactory( "RemExec" ) ); for ( final Client client : clients ) { if ( Util.isEmpty( client.clientip ) ) continue; diff --git a/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java b/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java index 2776732..c10c7e4 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java +++ b/src/main/java/org/openslx/taskmanager/tasks/RemoteReboot.java @@ -14,6 +14,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import org.openslx.taskmanager.api.AbstractTask; +import org.openslx.util.PrioThreadFactory; import com.google.gson.annotations.Expose; import com.jcraft.jsch.ChannelExec; @@ -106,7 +107,8 @@ public class RemoteReboot extends AbstractTask return true; final List<Client> rebootingClients = new ArrayList<>(); // try to connect to every client and start the reboot/shutdown process - ExecutorService tp = Executors.newFixedThreadPool( clients.length > 4 ? 4 : clients.length ); + ExecutorService tp = Executors.newFixedThreadPool( clients.length > 4 ? 4 : clients.length, + new PrioThreadFactory( "RemRebt" ) ); for ( final Client client : clients ) { if ( client == null || client.clientip == null || client.machineuuid == null ) { status.addError( "null Client or missing ip/uuid in list, ignoring." ); @@ -172,7 +174,7 @@ public class RemoteReboot extends AbstractTask tp.shutdown(); try { - tp.awaitTermination( clients.length * 5, TimeUnit.SECONDS ); + tp.awaitTermination( clients.length * 5 + 10, TimeUnit.SECONDS ); } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); return false; diff --git a/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java b/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java index 2d07db9..7562959 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java +++ b/src/main/java/org/openslx/taskmanager/tasks/WakeOnLan.java @@ -21,6 +21,7 @@ import org.openslx.satserver.util.WakeOnLanExecutor; import org.openslx.taskmanager.api.AbstractTask; import org.openslx.taskmanager.tasks.RemoteExec.Output; import org.openslx.taskmanager.tasks.RemoteExec.Result; +import org.openslx.util.PrioThreadFactory; import com.google.gson.annotations.Expose; @@ -79,7 +80,8 @@ public class WakeOnLan extends AbstractTask protected boolean execute() { // Loop over clients until they all were handled (i.e. methods is empty) - ExecutorService tp = Executors.newFixedThreadPool( Math.max( 1, Math.min( 4, ssh.size() ) ) ); + ExecutorService tp = Executors.newFixedThreadPool( Math.max( 1, Math.min( 4, ssh.size() ) ), + new PrioThreadFactory( "WOL" ) ); Map<String, ArrayList<String>> byMethod; int jobIdCounter = 0; do { |