TerrainGrid executor now prints out any exceptions from the threads
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9776 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
c3549f42f6
commit
7f740a0cd4
@ -46,13 +46,20 @@ import com.jme3.terrain.Terrain;
|
|||||||
import com.jme3.terrain.heightmap.HeightMap;
|
import com.jme3.terrain.heightmap.HeightMap;
|
||||||
import com.jme3.terrain.heightmap.HeightMapGrid;
|
import com.jme3.terrain.heightmap.HeightMapGrid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.Thread.UncaughtExceptionHandler;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.CancellationException;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -458,15 +465,42 @@ public class TerrainGrid extends TerrainQuad {
|
|||||||
return terrain.getMaterial(worldLocation);
|
return terrain.getMaterial(worldLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This will print out any exceptions from the thread
|
||||||
|
*/
|
||||||
protected ExecutorService createExecutorService() {
|
protected ExecutorService createExecutorService() {
|
||||||
return Executors.newSingleThreadExecutor(new ThreadFactory() {
|
final ThreadFactory threadFactory = new ThreadFactory() {
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
Thread th = new Thread(r);
|
Thread th = new Thread(r);
|
||||||
th.setName("jME Terrain Thread");
|
th.setName("jME TerrainGrid Thread");
|
||||||
th.setDaemon(true);
|
th.setDaemon(true);
|
||||||
return th;
|
return th;
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
ThreadPoolExecutor ex = new ThreadPoolExecutor(1, 1,
|
||||||
|
0L, TimeUnit.MILLISECONDS,
|
||||||
|
new LinkedBlockingQueue<Runnable>(),
|
||||||
|
threadFactory) {
|
||||||
|
protected void afterExecute(Runnable r, Throwable t) {
|
||||||
|
super.afterExecute(r, t);
|
||||||
|
if (t == null && r instanceof Future<?>) {
|
||||||
|
try {
|
||||||
|
Future<?> future = (Future<?>) r;
|
||||||
|
if (future.isDone())
|
||||||
|
future.get();
|
||||||
|
} catch (CancellationException ce) {
|
||||||
|
t = ce;
|
||||||
|
} catch (ExecutionException ee) {
|
||||||
|
t = ee.getCause();
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt(); // ignore/reset
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (t != null)
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user