Browse Source

* 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
Sha..rd 13 years ago
parent
commit
924d83ffdb
1 changed files with 16 additions and 32 deletions
  1. 16 32
      engine/src/core/com/jme3/asset/ThreadingManager.java

+ 16 - 32
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.*;
 
 /**
  * <code>ThreadingManager</code> 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<Object> {
-        private final String resourceName;
-        public LoadingTask(String resourceName){
-            this.resourceName = resourceName;
+    protected class LoadingTask<T> implements Callable<T> {
+
+        private final AssetKey<T> assetKey;
+
+        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> {
-//        private final String[] resourceNames;
-//        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 <T> Future<T> loadAsset(AssetKey<T> assetKey) {
+        return executor.submit(new LoadingTask(assetKey));
+    }
 
     public static boolean isLoadingThread() {
-        return Thread.currentThread().getName().startsWith("pool");
+        return Thread.currentThread().getName().startsWith("jME3-threadpool");
     }