From b1eb7ca6b9d7dec7ff62c1f1e8ef0a0545724d2f Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 18 Mar 2013 03:00:45 +0100 Subject: Function- RunnableTask: Add PrintStream 'exceptionOut' argument allowing non blocking exceptions to be shown. Exceptions occuring on non blocking off-thread tasks shall at least be made visible while not allowed to crash the system. --- src/java/com/jogamp/common/util/FunctionTask.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/java/com/jogamp/common/util/FunctionTask.java') diff --git a/src/java/com/jogamp/common/util/FunctionTask.java b/src/java/com/jogamp/common/util/FunctionTask.java index 35720a0..8238aff 100644 --- a/src/java/com/jogamp/common/util/FunctionTask.java +++ b/src/java/com/jogamp/common/util/FunctionTask.java @@ -28,6 +28,8 @@ package com.jogamp.common.util; +import java.io.PrintStream; + /** * Helper class to provide a Runnable queue implementation with a Runnable wrapper * which notifies after execution for the invokeAndWait() semantics. @@ -47,7 +49,7 @@ public class FunctionTask extends TaskBase implements Function { public static U invoke(boolean waitUntilDone, Function func, V... args) { Throwable throwable = null; final Object sync = new Object(); - final FunctionTask rt = new FunctionTask( func, waitUntilDone ? sync : null, true ); + final FunctionTask rt = new FunctionTask( func, waitUntilDone ? sync : null, true, waitUntilDone ? null : System.err ); final U res; synchronized(sync) { res = rt.eval(args); @@ -75,11 +77,13 @@ public class FunctionTask extends TaskBase implements Function { * @param runnable the user action * @param syncObject the synchronization object the caller shall wait until runnable execution is completed, * or null if waiting is not desired. - * @param catchExceptions if true, exception during runnable execution are catched, otherwise not. - * Use {@link #getThrowable()} to determine whether an exception has been catched. + * @param catchExceptions Influence an occurring exception during runnable execution. + * If true, the exception is silenced and can be retrieved via {@link #getThrowable()}, + * otherwise the exception is thrown. + * @param exceptionOut If not null, exceptions are written to this {@link PrintStream}. */ - public FunctionTask(Function runnable, Object syncObject, boolean catchExceptions) { - super(syncObject, catchExceptions); + public FunctionTask(Function runnable, Object syncObject, boolean catchExceptions, PrintStream exceptionOut) { + super(syncObject, catchExceptions, exceptionOut); this.runnable = runnable ; result = null; args = null; @@ -129,6 +133,9 @@ public class FunctionTask extends TaskBase implements Function { this.result = runnable.eval(args); } catch (Throwable t) { runnableException = t; + if(null != exceptionOut) { + t.printStackTrace(exceptionOut); + } if(!catchExceptions) { throw new RuntimeException(runnableException); } @@ -141,6 +148,9 @@ public class FunctionTask extends TaskBase implements Function { this.result = runnable.eval(args); } catch (Throwable t) { runnableException = t; + if(null != exceptionOut) { + t.printStackTrace(exceptionOut); + } if(!catchExceptions) { throw new RuntimeException(runnableException); } -- cgit v1.2.3