forked from j62/ctbrec
1
0
Fork 0

Revert "Use CompletableFuture.runAsync instead of creating new Threads"

This reverts commit 53684668ab.
This commit is contained in:
0xb00bface 2020-12-31 14:37:01 +01:00
parent 93a662ce22
commit d1764389f0
21 changed files with 83 additions and 86 deletions

View File

@ -14,7 +14,6 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -463,7 +462,7 @@ public class CamrecApplication extends Application {
} }
private void checkForUpdates() { private void checkForUpdates() {
CompletableFuture.runAsync(() -> { Thread updateCheck = new Thread(() -> {
String url = "https://pastebin.com/raw/mUxtKzyB"; String url = "https://pastebin.com/raw/mUxtKzyB";
Request request = new Request.Builder().url(url).build(); Request request = new Request.Builder().url(url).build();
try (Response response = httpClient.execute(request)) { try (Response response = httpClient.execute(request)) {
@ -490,6 +489,9 @@ public class CamrecApplication extends Application {
LOG.warn("Update check failed: {}", e.getMessage()); LOG.warn("Update check failed: {}", e.getMessage());
} }
}); });
updateCheck.setName("Update Check");
updateCheck.setDaemon(true);
updateCheck.start();
} }
public static Version getVersion() throws IOException { public static Version getVersion() throws IOException {

View File

@ -1,7 +1,6 @@
package ctbrec.ui; package ctbrec.ui;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -146,7 +145,7 @@ public class PreviewPopupHandler implements EventHandler<MouseEvent> {
} }
private void createTimerThread() { private void createTimerThread() {
CompletableFuture.runAsync(() -> { Thread timerThread = new Thread(() -> {
while(true) { while(true) {
openCountdown--; openCountdown--;
if(openCountdown == 0) { if(openCountdown == 0) {
@ -182,5 +181,9 @@ public class PreviewPopupHandler implements EventHandler<MouseEvent> {
} }
} }
}); });
timerThread.setDaemon(true);
timerThread.setPriority(Thread.MIN_PRIORITY);
timerThread.setName("PreviewPopupTimer");
timerThread.start();
} }
} }

View File

@ -4,7 +4,6 @@ import java.io.InputStream;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.function.Function; import java.util.function.Function;
@ -62,7 +61,7 @@ public class StreamSourceSelectionDialog {
} }
}); });
selectStreamSource.setOnFailed(e -> onFail.apply(selectStreamSource.getException())); selectStreamSource.setOnFailed(e -> onFail.apply(selectStreamSource.getException()));
CompletableFuture.runAsync(selectStreamSource); new Thread(selectStreamSource).start();
} }
private static class BestStreamSource extends StreamSource { private static class BestStreamSource extends StreamSource {

View File

@ -2,7 +2,6 @@ package ctbrec.ui;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -79,7 +78,7 @@ public class TipDialog extends TextInputDialog {
} }
} }
}; };
CompletableFuture.runAsync(task); new Thread(task).start();
} }
private void showErrorDialog(Throwable throwable) { private void showErrorDialog(Throwable throwable) {

View File

@ -3,7 +3,6 @@ package ctbrec.ui;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -84,6 +83,6 @@ public class TokenLabel extends Label {
} }
} }
}; };
CompletableFuture.runAsync(task); new Thread(task).start();
} }
} }

View File

@ -3,7 +3,6 @@ package ctbrec.ui.action;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -30,7 +29,7 @@ public class CheckModelAccountAction {
public void execute() { public void execute() {
String buttonText = b.getText(); String buttonText = b.getText();
b.setDisable(true); b.setDisable(true);
CompletableFuture.runAsync(() -> { Runnable checker = (() -> {
List<Model> deletedAccounts = new ArrayList<>(); List<Model> deletedAccounts = new ArrayList<>();
try { try {
List<Model> models = recorder.getModels(); List<Model> models = recorder.getModels();
@ -67,5 +66,6 @@ public class CheckModelAccountAction {
}); });
} }
}); });
new Thread(checker).start();
} }
} }

View File

@ -2,7 +2,6 @@ package ctbrec.ui.action;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -31,7 +30,7 @@ public class EditNotesAction {
public void execute() { public void execute() {
source.setCursor(Cursor.WAIT); source.setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> Platform.runLater(() -> { new Thread(() -> Platform.runLater(() -> {
String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), ""); String notes = Config.getInstance().getSettings().modelNotes.getOrDefault(model.getUrl(), "");
Optional<String> newNotes = Dialogs.showTextInput(source.getScene(), "Model Notes", "Notes for " + model.getName(), notes); Optional<String> newNotes = Dialogs.showTextInput(source.getScene(), "Model Notes", "Notes for " + model.getName(), notes);
newNotes.ifPresent(n -> { newNotes.ifPresent(n -> {
@ -48,6 +47,6 @@ public class EditNotesAction {
}); });
table.refresh(); table.refresh();
source.setCursor(Cursor.DEFAULT); source.setCursor(Cursor.DEFAULT);
})); })).start();
} }
} }

View File

@ -2,7 +2,11 @@ package ctbrec.ui.action;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
import ctbrec.Model; import ctbrec.Model;
@ -12,6 +16,9 @@ import javafx.scene.Node;
public class ModelMassEditAction { public class ModelMassEditAction {
static BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
static ExecutorService threadPool = new ThreadPoolExecutor(2, 10, 10, TimeUnit.MINUTES, queue);
protected List<? extends Model> models; protected List<? extends Model> models;
protected Consumer<Model> action; protected Consumer<Model> action;
protected Node source; protected Node source;
@ -35,7 +42,7 @@ public class ModelMassEditAction {
Consumer<Model> cb = Objects.requireNonNull(callback, "Callback is null, call execute() instead"); Consumer<Model> cb = Objects.requireNonNull(callback, "Callback is null, call execute() instead");
source.setCursor(Cursor.WAIT); source.setCursor(Cursor.WAIT);
for (Model model : models) { for (Model model : models) {
CompletableFuture.runAsync(() -> { threadPool.submit(() -> {
action.accept(model); action.accept(model);
cb.accept(model); cb.accept(model);
Platform.runLater(() -> source.setCursor(Cursor.DEFAULT)); Platform.runLater(() -> source.setCursor(Cursor.DEFAULT));

View File

@ -2,7 +2,6 @@ package ctbrec.ui.action;
import java.io.File; import java.io.File;
import java.time.Instant; import java.time.Instant;
import java.util.concurrent.CompletableFuture;
import ctbrec.Config; import ctbrec.Config;
import ctbrec.Model; import ctbrec.Model;
@ -27,7 +26,7 @@ public class OpenRecordingsDir {
File fileForRecording = Config.getInstance().getFileForRecording(selectedModel, ".mp4", Instant.now()); File fileForRecording = Config.getInstance().getFileForRecording(selectedModel, ".mp4", Instant.now());
final File dir = getModelDirectory(fileForRecording); final File dir = getModelDirectory(fileForRecording);
if (dir.exists()) { if (dir.exists()) {
CompletableFuture.runAsync(() -> DesktopIntegration.open(dir)); new Thread(() -> DesktopIntegration.open(dir)).start();
} else { } else {
Dialogs.showError(source.getScene(), "Directory does not exist", "There are no recordings for this model", null); Dialogs.showError(source.getScene(), "Directory does not exist", "There are no recordings for this model", null);
} }

View File

@ -1,7 +1,5 @@
package ctbrec.ui.action; package ctbrec.ui.action;
import java.util.concurrent.CompletableFuture;
import ctbrec.recorder.Recorder; import ctbrec.recorder.Recorder;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
import javafx.application.Platform; import javafx.application.Platform;
@ -22,7 +20,7 @@ public class ToggleRecordingAction {
public void execute() { public void execute() {
toggleButton.setCursor(Cursor.WAIT); toggleButton.setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { Thread t = new Thread(() -> {
try { try {
if (pause) { if (pause) {
recorder.pause(); recorder.pause();
@ -38,5 +36,7 @@ public class ToggleRecordingAction {
Platform.runLater(() -> toggleButton.setCursor(Cursor.DEFAULT)); Platform.runLater(() -> toggleButton.setCursor(Cursor.DEFAULT));
} }
}); });
t.setDaemon(true);
t.start();
} }
} }

View File

@ -34,7 +34,6 @@ package ctbrec.ui.controls;
import java.net.URL; import java.net.URL;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -168,7 +167,7 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
follow = new Button("Follow"); follow = new Button("Follow");
follow.setOnAction(evt -> { follow.setOnAction(evt -> {
setCursor(Cursor.WAIT); setCursor(Cursor.WAIT);
CompletableFuture.runAsync(new Task<Boolean>() { new Thread(new Task<Boolean>() {
@Override @Override
protected Boolean call() throws Exception { protected Boolean call() throws Exception {
model.getSite().login(); model.getSite().login();
@ -184,12 +183,12 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
} }
Platform.runLater(() -> setCursor(Cursor.DEFAULT)); Platform.runLater(() -> setCursor(Cursor.DEFAULT));
} }
}); }).start();
}); });
record = new Button("Record"); record = new Button("Record");
record.setOnAction(evt -> { record.setOnAction(evt -> {
setCursor(Cursor.WAIT); setCursor(Cursor.WAIT);
CompletableFuture.runAsync(new Task<Void>() { new Thread(new Task<Void>() {
@Override @Override
protected Void call() throws Exception { protected Void call() throws Exception {
recorder.startRecording(model); recorder.startRecording(model);
@ -200,7 +199,7 @@ public class SearchPopoverTreeList extends PopoverTreeList<Model> implements Pop
protected void done() { protected void done() {
Platform.runLater(() -> setCursor(Cursor.DEFAULT)); Platform.runLater(() -> setCursor(Cursor.DEFAULT));
} }
}); }).start();
}); });
getChildren().addAll(thumb, title, follow, record); getChildren().addAll(thumb, title, follow, record);

View File

@ -3,7 +3,6 @@ package ctbrec.ui.controls;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -158,14 +157,14 @@ public class StreamPreview extends StackPane {
running = false; running = false;
MediaPlayer old = videoPlayer; MediaPlayer old = videoPlayer;
Future<?> oldFuture = future; Future<?> oldFuture = future;
CompletableFuture.runAsync(() -> { new Thread(() -> {
if(oldFuture != null && !oldFuture.isDone()) { if(oldFuture != null && !oldFuture.isDone()) {
oldFuture.cancel(true); oldFuture.cancel(true);
} }
if(old != null) { if(old != null) {
old.dispose(); old.dispose();
} }
}); }).start();
} }
private void onError(MediaPlayer videoPlayer) { private void onError(MediaPlayer videoPlayer) {

View File

@ -1,7 +1,5 @@
package ctbrec.ui.controls; package ctbrec.ui.controls;
import java.util.concurrent.CompletableFuture;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.KeyValue; import javafx.animation.KeyValue;
import javafx.animation.Timeline; import javafx.animation.Timeline;
@ -38,7 +36,7 @@ public final class Toast {
KeyFrame fadeInKey1 = new KeyFrame(Duration.millis(fadeInDelay), new KeyValue(toastStage.getScene().getRoot().opacityProperty(), 1)); KeyFrame fadeInKey1 = new KeyFrame(Duration.millis(fadeInDelay), new KeyValue(toastStage.getScene().getRoot().opacityProperty(), 1));
fadeInTimeline.getKeyFrames().add(fadeInKey1); fadeInTimeline.getKeyFrames().add(fadeInKey1);
fadeInTimeline.setOnFinished((ae) -> { fadeInTimeline.setOnFinished((ae) -> {
CompletableFuture.runAsync(() -> { new Thread(() -> {
try { try {
Thread.sleep(toastDelay); Thread.sleep(toastDelay);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -49,7 +47,7 @@ public final class Toast {
fadeOutTimeline.getKeyFrames().add(fadeOutKey1); fadeOutTimeline.getKeyFrames().add(fadeOutKey1);
fadeOutTimeline.setOnFinished((aeb) -> toastStage.close()); fadeOutTimeline.setOnFinished((aeb) -> toastStage.close());
fadeOutTimeline.play(); fadeOutTimeline.play();
}); }).start();
}); });
fadeInTimeline.play(); fadeInTimeline.play();
} }

View File

@ -1,16 +1,7 @@
package ctbrec.ui.news; package ctbrec.ui.news;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import org.json.JSONObject;
import com.squareup.moshi.JsonAdapter; import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.Moshi; import com.squareup.moshi.Moshi;
import ctbrec.io.HttpException; import ctbrec.io.HttpException;
import ctbrec.ui.CamrecApplication; import ctbrec.ui.CamrecApplication;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
@ -23,6 +14,12 @@ import javafx.scene.control.Tab;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import org.json.JSONObject;
import java.io.IOException;
import java.util.Objects;
import static ctbrec.io.HttpConstants.USER_AGENT;
public class NewsTab extends Tab implements TabSelectionListener { public class NewsTab extends Tab implements TabSelectionListener {
private static final String ACCESS_TOKEN = "a2804d73a89951a22e0f8483a6fcec8943afd88b7ba17c459c095aa9e6f94fd0"; private static final String ACCESS_TOKEN = "a2804d73a89951a22e0f8483a6fcec8943afd88b7ba17c459c095aa9e6f94fd0";
@ -39,7 +36,7 @@ public class NewsTab extends Tab implements TabSelectionListener {
@Override @Override
public void selected() { public void selected() {
CompletableFuture.runAsync(this::loadToots); new Thread(this::loadToots).start();
} }
private void loadToots() { private void loadToots() {

View File

@ -1,19 +1,17 @@
package ctbrec.ui.sites.bonga; package ctbrec.ui.sites.bonga;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.sites.bonga.BongaCams; import ctbrec.sites.bonga.BongaCams;
import ctbrec.sites.bonga.BongaCamsHttpClient; import ctbrec.sites.bonga.BongaCamsHttpClient;
import ctbrec.ui.controls.Dialogs; import ctbrec.ui.controls.Dialogs;
import ctbrec.ui.sites.AbstractSiteUi; import ctbrec.ui.sites.AbstractSiteUi;
import ctbrec.ui.sites.ConfigUI; import ctbrec.ui.sites.ConfigUI;
import ctbrec.ui.tabs.TabProvider; import ctbrec.ui.tabs.TabProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class BongaCamsSiteUi extends AbstractSiteUi { public class BongaCamsSiteUi extends AbstractSiteUi {
@ -46,7 +44,7 @@ public class BongaCamsSiteUi extends AbstractSiteUi {
} else { } else {
BlockingQueue<Boolean> queue = new LinkedBlockingQueue<>(); BlockingQueue<Boolean> queue = new LinkedBlockingQueue<>();
try { try {
CompletableFuture.runAsync(() -> { new Thread(() -> {
// login with external browser window // login with external browser window
try { try {
new BongaCamsElectronLoginDialog(bongaCams.getHttpClient().getCookieJar()); new BongaCamsElectronLoginDialog(bongaCams.getHttpClient().getCookieJar());
@ -61,7 +59,7 @@ public class BongaCamsSiteUi extends AbstractSiteUi {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
LOG.error("Error while signaling termination", e); LOG.error("Error while signaling termination", e);
} }
}); }).start();
queue.take(); queue.take();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();

View File

@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -137,7 +136,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
}); });
} }
}; };
CompletableFuture.runAsync(task); new Thread(task).start();
} }
@Override @Override
@ -203,7 +202,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
private void follow(Model model) { private void follow(Model model) {
setCursor(Cursor.WAIT); setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { new Thread(() -> {
try { try {
SiteUiFactory.getUi(model.getSite()).login(); SiteUiFactory.getUi(model.getSite()).login();
model.follow(); model.follow();
@ -215,12 +214,12 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
setCursor(Cursor.DEFAULT); setCursor(Cursor.DEFAULT);
}); });
} }
}); }).start();
} }
private void record(Model model) { private void record(Model model) {
setCursor(Cursor.WAIT); setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { new Thread(() -> {
try { try {
recorder.startRecording(model); recorder.startRecording(model);
} catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) { } catch (InvalidKeyException | NoSuchAlgorithmException | IllegalStateException | IOException e) {
@ -230,11 +229,11 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
setCursor(Cursor.DEFAULT); setCursor(Cursor.DEFAULT);
}); });
} }
}); }).start();
} }
private void loadImage(Model model, ImageView thumb) { private void loadImage(Model model, ImageView thumb) {
CompletableFuture.runAsync(() -> { new Thread(() -> {
try { try {
String url = camsoda.getBaseUrl() + "/api/v1/user/" + model.getName(); String url = camsoda.getBaseUrl() + "/api/v1/user/" + model.getName();
Request detailRequest = new Request.Builder().url(url).build(); Request detailRequest = new Request.Builder().url(url).build();
@ -271,7 +270,7 @@ public class CamsodaShowsTab extends Tab implements TabSelectionListener {
} catch (Exception e) { } catch (Exception e) {
LOG.error("Couldn't load model details", e); LOG.error("Couldn't load model details", e);
} }
}); }).start();
} }
private Node createLabel(String string, boolean bold) { private Node createLabel(String string, boolean bold) {

View File

@ -2,7 +2,6 @@ package ctbrec.ui.sites.jasmin;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -56,7 +55,7 @@ public class LiveJasminSiteUi extends AbstractSiteUi {
lastLoginTime = System.currentTimeMillis(); lastLoginTime = System.currentTimeMillis();
BlockingQueue<Boolean> queue = new LinkedBlockingQueue<>(); BlockingQueue<Boolean> queue = new LinkedBlockingQueue<>();
CompletableFuture.runAsync(() -> { new Thread (() -> {
// login with external browser window // login with external browser window
try { try {
new LiveJasminElectronLoginDialog(liveJasmin.getHttpClient().getCookieJar()); new LiveJasminElectronLoginDialog(liveJasmin.getHttpClient().getCookieJar());
@ -70,7 +69,7 @@ public class LiveJasminSiteUi extends AbstractSiteUi {
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOG.error("Error while signaling termination", e); LOG.error("Error while signaling termination", e);
} }
}); }).start();
try { try {
queue.take(); queue.take();

View File

@ -18,7 +18,6 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -353,7 +352,7 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
if (Objects.equals(System.getenv("CTBREC_DEV"), "1")) { if (Objects.equals(System.getenv("CTBREC_DEV"), "1")) {
MenuItem debug = new MenuItem("debug"); MenuItem debug = new MenuItem("debug");
debug.setOnAction(e -> CompletableFuture.runAsync(() -> { debug.setOnAction(e -> new Thread(() -> {
for (Model m : selectedModels) { for (Model m : selectedModels) {
try { try {
List<StreamSource> sources = m.getStreamSources(); List<StreamSource> sources = m.getStreamSources();
@ -365,7 +364,7 @@ public class MyFreeCamsTableTab extends Tab implements TabSelectionListener {
LOG.error("Couldn't get stream sources", e1); LOG.error("Couldn't get stream sources", e1);
} }
} }
})); }).start());
menu.getItems().add(debug); menu.getItems().add(debug);
} }

View File

@ -2,7 +2,6 @@ package ctbrec.ui.sites.showup;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -47,7 +46,7 @@ public class ShowupSiteUi extends AbstractSiteUi {
} else { } else {
BlockingQueue<Boolean> queue = new LinkedBlockingQueue<>(); BlockingQueue<Boolean> queue = new LinkedBlockingQueue<>();
try { try {
CompletableFuture.runAsync(() -> { new Thread(() -> {
// login with external browser window // login with external browser window
try { try {
new ShowupElectronLoginDialog(site.getHttpClient().getCookieJar()); new ShowupElectronLoginDialog(site.getHttpClient().getCookieJar());
@ -62,7 +61,7 @@ public class ShowupSiteUi extends AbstractSiteUi {
LOG.error("Error while signaling termination", e); LOG.error("Error while signaling termination", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
}); }).start();
queue.take(); queue.take();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();

View File

@ -17,7 +17,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -498,9 +497,9 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
private void openContactSheet(JavaFxRecording recording) { private void openContactSheet(JavaFxRecording recording) {
if (config.getSettings().localRecording) { if (config.getSettings().localRecording) {
recording.getContactSheet().ifPresent(f -> CompletableFuture.runAsync(() -> DesktopIntegration.open(f))); recording.getContactSheet().ifPresent(f -> new Thread(() -> DesktopIntegration.open(f)).start());
} else { } else {
recording.getContactSheet().ifPresent(f -> CompletableFuture.runAsync(() -> { recording.getContactSheet().ifPresent(f -> new Thread(() -> {
File target; File target;
try { try {
target = File.createTempFile("cs_", ".jpg"); target = File.createTempFile("cs_", ".jpg");
@ -518,7 +517,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
} catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e) { } catch (IOException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException e) {
Dialogs.showError(getTabPane().getScene(), "Download Error", "An error occurred while downloading the contact sheet", e); Dialogs.showError(getTabPane().getScene(), "Download Error", "An error occurred while downloading the contact sheet", e);
} }
})); }).start());
} }
} }
@ -528,7 +527,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
Optional<String> newNote = Dialogs.showTextInput(source.getScene(), "Recording Notes", "", notes); Optional<String> newNote = Dialogs.showTextInput(source.getScene(), "Recording Notes", "", notes);
if (newNote.isPresent()) { if (newNote.isPresent()) {
table.setCursor(Cursor.WAIT); table.setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { Thread backgroundThread = new Thread(() -> {
List<Exception> exceptions = new ArrayList<>(); List<Exception> exceptions = new ArrayList<>();
try { try {
recording.setNote(newNote.get()); recording.setNote(newNote.get());
@ -544,12 +543,13 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
}); });
} }
}); });
backgroundThread.start();
} }
} }
private void pin(List<JavaFxRecording> recordings) { private void pin(List<JavaFxRecording> recordings) {
table.setCursor(Cursor.WAIT); table.setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { Thread backgroundThread = new Thread(() -> {
List<Exception> exceptions = new ArrayList<>(); List<Exception> exceptions = new ArrayList<>();
try { try {
for (JavaFxRecording javaFxRecording : recordings) { for (JavaFxRecording javaFxRecording : recordings) {
@ -570,11 +570,12 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
}); });
} }
}); });
backgroundThread.start();
} }
private void unpin(List<JavaFxRecording> recordings) { private void unpin(List<JavaFxRecording> recordings) {
table.setCursor(Cursor.WAIT); table.setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { Thread backgroundThread = new Thread(() -> {
List<Exception> exceptions = new ArrayList<>(); List<Exception> exceptions = new ArrayList<>();
try { try {
for (JavaFxRecording javaFxRecording : recordings) { for (JavaFxRecording javaFxRecording : recordings) {
@ -595,6 +596,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
}); });
} }
}); });
backgroundThread.start();
} }
private void jumpToNextModel(KeyCode code) { private void jumpToNextModel(KeyCode code) {
@ -645,11 +647,11 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
private void onOpenDirectory(JavaFxRecording first) { private void onOpenDirectory(JavaFxRecording first) {
File tsFile = first.getAbsoluteFile(); File tsFile = first.getAbsoluteFile();
CompletableFuture.runAsync(() -> DesktopIntegration.open(tsFile.getParent())); new Thread(() -> DesktopIntegration.open(tsFile.getParent())).start();
} }
private void triggerPostProcessing(List<JavaFxRecording> recs) { private void triggerPostProcessing(List<JavaFxRecording> recs) {
CompletableFuture.runAsync(() -> { new Thread(() -> {
for (JavaFxRecording rec : recs) { for (JavaFxRecording rec : recs) {
try { try {
recorder.rerunPostProcessing(rec.getDelegate()); recorder.rerunPostProcessing(rec.getDelegate());
@ -658,7 +660,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
LOG.error("Error while starting post-processing", e1); LOG.error("Error while starting post-processing", e1);
} }
} }
}); }).start();
} }
private void download(Recording recording) { private void download(Recording recording) {
@ -794,7 +796,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
} }
private void deleteAsync(List<JavaFxRecording> recordings) { private void deleteAsync(List<JavaFxRecording> recordings) {
CompletableFuture.runAsync(() -> { Thread deleteThread = new Thread(() -> {
recordingsLock.lock(); recordingsLock.lock();
try { try {
List<Recording> deleted = new ArrayList<>(); List<Recording> deleted = new ArrayList<>();
@ -820,6 +822,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
Platform.runLater(() -> table.setCursor(Cursor.DEFAULT)); Platform.runLater(() -> table.setCursor(Cursor.DEFAULT));
} }
}); });
deleteThread.start();
} }
public void saveState() { public void saveState() {

View File

@ -484,7 +484,7 @@ public class ThumbCell extends StackPane {
void pauseResumeAction(boolean pause) { void pauseResumeAction(boolean pause) {
setCursor(Cursor.WAIT); setCursor(Cursor.WAIT);
CompletableFuture.runAsync(() -> { new Thread(() -> {
try { try {
if (pause) { if (pause) {
recorder.suspendRecording(model); recorder.suspendRecording(model);
@ -504,11 +504,11 @@ public class ThumbCell extends StackPane {
} finally { } finally {
Platform.runLater(() -> setCursor(Cursor.DEFAULT)); Platform.runLater(() -> setCursor(Cursor.DEFAULT));
} }
}); }).start();
} }
private void startStopActionAsync(Model model, boolean start) { private void startStopActionAsync(Model model, boolean start) {
CompletableFuture.runAsync(() -> { new Thread(() -> {
try { try {
if (start) { if (start) {
recorder.startRecording(model); recorder.startRecording(model);
@ -523,7 +523,7 @@ public class ThumbCell extends StackPane {
} finally { } finally {
Platform.runLater(() -> setCursor(Cursor.DEFAULT)); Platform.runLater(() -> setCursor(Cursor.DEFAULT));
} }
}); }).start();
} }
CompletableFuture<Boolean> follow(boolean follow) { CompletableFuture<Boolean> follow(boolean follow) {