diff --git a/engine/src/core/com/jme3/asset/ThreadingManager.java b/engine/src/core/com/jme3/asset/ThreadingManager.java index 6ed2c742e..26cac5fcd 100644 --- a/engine/src/core/com/jme3/asset/ThreadingManager.java +++ b/engine/src/core/com/jme3/asset/ThreadingManager.java @@ -32,10 +32,7 @@ package com.jme3.asset; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadFactory; +import java.util.concurrent.*; /** * ThreadingManager manages the threads used to load content @@ -46,11 +43,10 @@ import java.util.concurrent.ThreadFactory; public class ThreadingManager { protected final ExecutorService executor = - Executors.newFixedThreadPool(2, + Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new LoadingThreadFactory()); protected final AssetManager owner; - protected int nextThreadId = 0; public ThreadingManager(AssetManager owner){ @@ -59,44 +55,32 @@ public class ThreadingManager { protected class LoadingThreadFactory implements ThreadFactory { public Thread newThread(Runnable r) { - Thread t = new Thread(r, "pool" + (nextThreadId++)); + Thread t = new Thread(r, "jME3-threadpool-" + (nextThreadId++)); t.setDaemon(true); t.setPriority(Thread.MIN_PRIORITY); return t; } } - protected class LoadingTask implements Callable { - private final String resourceName; - public LoadingTask(String resourceName){ - this.resourceName = resourceName; + protected class LoadingTask implements Callable { + + private final AssetKey assetKey; + + public LoadingTask(AssetKey assetKey) { + this.assetKey = assetKey; } - public Object call() throws Exception { - return owner.loadAsset(new AssetKey(resourceName)); + + public T call() throws Exception { + return owner.loadAsset(assetKey); } } -// protected class MultiLoadingTask implements Callable { -// private final String[] resourceNames; -// public MultiLoadingTask(String[] resourceNames){ -// this.resourceNames = resourceNames; -// } -// public Void call(){ -// owner.loadContents(resourceNames); -// return null; -// } -// } - -// public Future loadContents(String ... names){ -// return executor.submit(new MultiLoadingTask(names)); -// } - -// public Future loadContent(String name) { -// return executor.submit(new LoadingTask(name)); -// } + public Future loadAsset(AssetKey assetKey) { + return executor.submit(new LoadingTask(assetKey)); + } public static boolean isLoadingThread() { - return Thread.currentThread().getName().startsWith("pool"); + return Thread.currentThread().getName().startsWith("jME3-threadpool"); }