Skip to content

Commit

Permalink
Remove asset loader thread pool
Browse files Browse the repository at this point in the history
It was only used in getAssetAsynchronously
which spawned a task that either returns after finding the asset in the
cache or added a task to another thread pool.

Determining if a file exists is potentially slow on Windows
and this thread pool potentially allowed the caller to be reponsive
but it's also a source of potential deadlocks if the listener callback
indirectly requests an asset load
such as an addon's onInit script loading the JavaScript asset.

The git logs don't go far enough back to determine whether the thread
pool is intentional or vestigial.
  • Loading branch information
fishface60 committed Jan 26, 2025
1 parent b02a6a5 commit e683c6c
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/main/java/net/rptools/maptool/model/AssetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ 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 assetWriterThreadPool = Executors.newFixedThreadPool(1);

static {
Expand Down Expand Up @@ -286,25 +285,22 @@ public static void putAsset(Asset asset) {
public static void getAssetAsynchronously(
final MD5Key id, final AssetAvailableListener... listeners) {

assetLoaderThreadPool.submit(
() -> {
Asset asset = getAsset(id);
Asset asset = getAsset(id);

// Simplest case, we already have it
if (asset != null && asset.getData() != null && asset.getData().length > 0) {
for (AssetAvailableListener listener : listeners) {
listener.assetAvailable(id);
}
// Simplest case, we already have it
if (asset != null && asset.getData() != null && asset.getData().length > 0) {
for (AssetAvailableListener listener : listeners) {
listener.assetAvailable(id);
}

return;
}
return;
}

// Let's get it from the server
// As a last resort we request the asset from the server
if (!isAssetRequested(id)) {
requestAssetFromServer(id, listeners);
}
});
// Let's get it from the server
// As a last resort we request the asset from the server
if (!isAssetRequested(id)) {
requestAssetFromServer(id, listeners);
}
}

/**
Expand Down

0 comments on commit e683c6c

Please sign in to comment.