* Fixed up ThreadingManager to actually work with the asset manager, even though nobody uses it
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9310 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
bd4214f3bd
commit
924d83ffdb
@ -32,10 +32,7 @@
|
|||||||
|
|
||||||
package com.jme3.asset;
|
package com.jme3.asset;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>ThreadingManager</code> manages the threads used to load content
|
* <code>ThreadingManager</code> manages the threads used to load content
|
||||||
@ -46,11 +43,10 @@ import java.util.concurrent.ThreadFactory;
|
|||||||
public class ThreadingManager {
|
public class ThreadingManager {
|
||||||
|
|
||||||
protected final ExecutorService executor =
|
protected final ExecutorService executor =
|
||||||
Executors.newFixedThreadPool(2,
|
Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
|
||||||
new LoadingThreadFactory());
|
new LoadingThreadFactory());
|
||||||
|
|
||||||
protected final AssetManager owner;
|
protected final AssetManager owner;
|
||||||
|
|
||||||
protected int nextThreadId = 0;
|
protected int nextThreadId = 0;
|
||||||
|
|
||||||
public ThreadingManager(AssetManager owner){
|
public ThreadingManager(AssetManager owner){
|
||||||
@ -59,44 +55,32 @@ public class ThreadingManager {
|
|||||||
|
|
||||||
protected class LoadingThreadFactory implements ThreadFactory {
|
protected class LoadingThreadFactory implements ThreadFactory {
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
Thread t = new Thread(r, "pool" + (nextThreadId++));
|
Thread t = new Thread(r, "jME3-threadpool-" + (nextThreadId++));
|
||||||
t.setDaemon(true);
|
t.setDaemon(true);
|
||||||
t.setPriority(Thread.MIN_PRIORITY);
|
t.setPriority(Thread.MIN_PRIORITY);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class LoadingTask implements Callable<Object> {
|
protected class LoadingTask<T> implements Callable<T> {
|
||||||
private final String resourceName;
|
|
||||||
public LoadingTask(String resourceName){
|
private final AssetKey<T> assetKey;
|
||||||
this.resourceName = resourceName;
|
|
||||||
|
public LoadingTask(AssetKey<T> 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<Void> {
|
public <T> Future<T> loadAsset(AssetKey<T> assetKey) {
|
||||||
// private final String[] resourceNames;
|
return executor.submit(new LoadingTask(assetKey));
|
||||||
// public MultiLoadingTask(String[] resourceNames){
|
}
|
||||||
// this.resourceNames = resourceNames;
|
|
||||||
// }
|
|
||||||
// public Void call(){
|
|
||||||
// owner.loadContents(resourceNames);
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Future<Void> loadContents(String ... names){
|
|
||||||
// return executor.submit(new MultiLoadingTask(names));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Future<Object> loadContent(String name) {
|
|
||||||
// return executor.submit(new LoadingTask(name));
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static boolean isLoadingThread() {
|
public static boolean isLoadingThread() {
|
||||||
return Thread.currentThread().getName().startsWith("pool");
|
return Thread.currentThread().getName().startsWith("jME3-threadpool");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user