Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a variable sized thread pool in AssetManager #5153

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Load assets in parallel
The getAssetAsynchronous method uses a thread pool so that requests to
load assets don't block networking threads etc.

It has been a single thread pool through the existing git history
but it is assumed that it is like this because it used to have a thread
and then was converted to use a single thread fixed thread pool.

Unfortunately having a single thread only means that if an asset load
callback indirectly loads another asset then this can deadlock
since the asset loader thread needs to be released before the load
request can start, which it can't because that thread is waiting for the
result of loading the new asset, thus it deadlocks if an AddOn includes
a JavaScript onInit script since it deadlocks waiting to load that
script.

Changing the thread pool so that the threads load in parallel is an
observable change that could cause problems,
but if the AddOn isn't already loaded the addonLoader's thread pool
loads it instead and that works fine,
so MapTool should be alright with addons and other assets loading in
parallel.
fishface60 committed Jan 28, 2025
commit bce0ff546660b64f00a2e557772b00c8d15d77e5
3 changes: 2 additions & 1 deletion src/main/java/net/rptools/maptool/model/AssetManager.java
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import net.rptools.lib.FileUtil;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.client.AppUtil;
@@ -90,7 +91,7 @@ public class AssetManager {
/** Used to load assets from storage */
private static AssetLoader assetLoader = new AssetLoader();

private static ExecutorService assetLoaderThreadPool = Executors.newFixedThreadPool(1);
private static ExecutorService assetLoaderThreadPool = ForkJoinPool.commonPool();
private static ExecutorService assetWriterThreadPool = Executors.newFixedThreadPool(1);

static {