Skip to content

Commit

Permalink
refactor executors to use daemon threads
Browse files Browse the repository at this point in the history
  • Loading branch information
Sesu8642 committed Sep 9, 2024
1 parent 139fbc9 commit d466776
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public void create() {

@Override
public void dispose() {
// shutdown executor services to kill all background threads
component.getBotAiExecutor().shutdownNow();
component.getCopyButtonExecutor().shutdownNow();
super.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

package de.sesu8642.feudaltactics.dagger;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;

import javax.inject.Singleton;

import dagger.Component;
Expand All @@ -31,10 +28,6 @@ public interface FeudalTacticsComponent {

GameInitializer getGameInitializer();

ExecutorService getBotAiExecutor();

ScheduledExecutorService getCopyButtonExecutor();

GameCrasher getGameCrasher();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

package de.sesu8642.feudaltactics.dagger;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import javax.inject.Singleton;

import org.slf4j.Logger;
Expand All @@ -14,7 +11,6 @@
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.SubscriberExceptionContext;
import com.google.common.eventbus.SubscriberExceptionHandler;
import com.ray3k.stripe.FreeTypeSkin;

Expand All @@ -33,14 +29,11 @@ private MainDaggerModule() {
@Provides
@Singleton
static EventBus provideEventBus() {
return new EventBus(new SubscriberExceptionHandler() {
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
Logger logger = LoggerFactory.getLogger(SubscriberExceptionHandler.class.getName());
logger.error(String.format(
"an unexpected error happened while handling the event %s in method %s of subscriber %s",
context.getEvent(), context.getSubscriberMethod(), context.getSubscriber()), exception);
}
return new EventBus((exception, context) -> {
Logger logger = LoggerFactory.getLogger(SubscriberExceptionHandler.class.getName());
logger.error(String.format(
"an unexpected error happened while handling the event %s in method %s of subscriber %s",
context.getEvent(), context.getSubscriberMethod(), context.getSubscriber()), exception);
});
}

Expand All @@ -55,10 +48,4 @@ static InputMultiplexer provideInputMultiplexer() {
return new InputMultiplexer();
}

@Provides
@Singleton
static ScheduledExecutorService provideCopyButtonFeedbackExecutorService() {
return Executors.newSingleThreadScheduledExecutor();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ static Preferences provideIncrementalAutoSavePrefStore(@PreferencesPrefixPropert
@Provides
@Singleton
static ExecutorService provideBotAiExecutor() {
return Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("botai-%d").build());
return Executors
.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("botai-%d").setDaemon(true).build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.ScheduledExecutorService;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -46,8 +45,7 @@ public class CrashReportScreen extends GameScreen {
/** Constructor. */
@Inject
public CrashReportScreen(EventBus eventBus, @MenuCamera OrthographicCamera camera, @MenuViewport Viewport viewport,
CrashReportStage crashReportStage, CrashReportDao crashReportDao,
ScheduledExecutorService copyButtonFeedbackExecutorService) {
CrashReportStage crashReportStage, CrashReportDao crashReportDao) {
super(camera, viewport, crashReportStage);
this.eventBus = eventBus;
this.crashReportStage = crashReportStage;
Expand Down

0 comments on commit d466776

Please sign in to comment.