Top Description Inners Constructors Methods
com.jogamp.opengl

public Class Threading

extends Object
Class Inheritance
Imports
jogamp.opengl.ThreadingImpl

This API provides access to the threading model for the implementation of the classes in this package.

OpenGL is specified as a thread-safe API, but in practice there are multithreading-related issues on most, if not all, of the platforms which support it. For example, some OpenGL implementations do not behave well when one context is made current first on one thread, released, and then made current on a second thread, although this is legal according to the OpenGL specification. On other platforms there are other problems.

Due to these limitations, and due to the inherent multithreading in the Java platform (in particular, in the Abstract Window Toolkit), it is often necessary to limit the multithreading occurring in the typical application using the OpenGL API.

In the current reference implementation, for instance, multithreading has been limited by forcing all OpenGL-related work for GLAutoDrawables on to a single thread. In other words, if an application uses only the GLAutoDrawable and GLEventListener callback mechanism, it is guaranteed to have the most correct single-threaded behavior on all platforms.

Applications using the GLContext makeCurrent/release API directly will inherently break this single-threaded model, as these methods require that the OpenGL context be made current on the current thread immediately. For applications wishing to integrate better with an implementation that uses the single-threaded model, this class provides public access to the mechanism used by the implementation.

Users can execute Runnables on the internal thread used for performing OpenGL work, and query whether the current thread is already this thread. Using these mechanisms the user can move work from the current thread on to the internal OpenGL thread if desired.

This class also provides mechanisms for querying whether this internal serialization of OpenGL work is in effect, and a programmatic way of disabling it. In the current reference implementation it is enabled by default, although it could be disabled in the future if OpenGL drivers become more robust on all platforms.

In addition to specifying programmatically whether the single thread for OpenGL work is enabled, users may switch it on and off using the system property jogl.1thread. Valid values for this system property are:

-Djogl.1thread=false     Disable single-threading of OpenGL work, hence use multithreading.
-Djogl.1thread=true      Enable single-threading of OpenGL work (default -- on a newly-created worker thread)
-Djogl.1thread=auto      Select default single-threading behavior (currently on)
-Djogl.1thread=awt       Enable single-threading of OpenGL work on AWT event dispatch thread (current default on all
                         platforms, and also the default behavior older releases)
-Djogl.1thread=worker    Enable single-threading of OpenGL work on newly-created worker thread (not suitable for Mac
                         OS X or X11 platforms, and risky on Windows in applet environments)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Constructor Summary

AccessConstructor and Description
private
Threading()

No reason to ever instantiate this class

Method Summary

Modifier and TypeMethod and Description
public static final void
disableSingleThreading()

If an implementation of the com.jogamp.opengl APIs offers a multithreading option but the default behavior is single-threading, this API provides a mechanism for end users to disable single-threading in this implementation.

public static Threading.Mode
getMode()

Returns the threading mode

public static final void
invoke(final boolean
set to true for waiting until Runnable r is finished, otherwise false.
wait
,
final Runnable
the Runnable to be executed
r
,
final Object
optional lock object to be tested
lock
)

If not isOpenGLThread() and the lock is not being hold by this thread, invoke Runnable r on the OpenGL thread via invokeOnOpenGLThread(boolean, Runnable).

public static final void
invokeOnOpenGLThread(final boolean wait, final Runnable r)

Executes the passed Runnable on the single thread used for all OpenGL work in this com.jogamp.opengl API implementation.

public static final boolean
isOpenGLThread()

Indicates whether the current thread is capable of performing OpenGL-related work.

public static final boolean
isSingleThreaded()

Indicates whether OpenGL work is being automatically forced to a single thread in this implementation.

public static final boolean
isToolkitThread()

Indicates whether the current thread is the designated toolkit thread, if such semantics exists.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Threadingback to summary
private Threading()

No reason to ever instantiate this class

Method Detail

disableSingleThreadingback to summary
public static final void disableSingleThreading()

If an implementation of the com.jogamp.opengl APIs offers a multithreading option but the default behavior is single-threading, this API provides a mechanism for end users to disable single-threading in this implementation. Users are strongly discouraged from calling this method unless they are aware of all of the consequences and are prepared to enforce some amount of threading restrictions in their applications. Disabling single-threading, for example, may have unintended consequences on GLAutoDrawable implementations such as GLCanvas and GLJPanel. Currently there is no supported way to re-enable it once disabled, partly to discourage careless use of this method. This method should be called as early as possible in an application.

getModeback to summary
public static Threading.Mode getMode()

Returns the threading mode

invokeback to summary
public static final void invoke(final boolean wait, final Runnable r, final Object lock) throws GLException

If not isOpenGLThread() and the lock is not being hold by this thread, invoke Runnable r on the OpenGL thread via invokeOnOpenGLThread(boolean, Runnable).

Otherwise invoke Runnable r on the current thread.

Parameters
wait:boolean

set to true for waiting until Runnable r is finished, otherwise false.

r:Runnable

the Runnable to be executed

lock:Object

optional lock object to be tested

invokeOnOpenGLThreadback to summary
public static final void invokeOnOpenGLThread(final boolean wait, final Runnable r) throws GLException

Executes the passed Runnable on the single thread used for all OpenGL work in this com.jogamp.opengl API implementation. It is not specified exactly which thread is used for this purpose. This method should only be called if the single-thread model is in use and if the current thread is not the OpenGL thread (i.e., if isOpenGLThread() returns false). It is up to the end user to check to see whether the current thread is the OpenGL thread and either execute the Runnable directly or perform the work inside it.

isOpenGLThreadback to summary
public static final boolean isOpenGLThread() throws GLException

Indicates whether the current thread is capable of performing OpenGL-related work.

Method always returns true if getMode() == Mode#MT or isSingleThreaded() == false.

isSingleThreadedback to summary
public static final boolean isSingleThreaded()

Indicates whether OpenGL work is being automatically forced to a single thread in this implementation.

isToolkitThreadback to summary
public static final boolean isToolkitThread() throws GLException

Indicates whether the current thread is the designated toolkit thread, if such semantics exists.

com.jogamp.opengl back to summary

public final Enum Threading.Mode

extends Enum<Threading.Mode>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public final int
public static final Threading.Mode
MT

Full multithreaded OpenGL, i.e. any invoke commands will be issued on the current thread immediately.

public static final Threading.Mode
ST_AWT

Single-Threaded OpenGL on AWT EDT

public static final Threading.Mode
ST_WORKER

Single-Threaded OpenGL on dedicated worker thread.

Constructor Summary

AccessConstructor and Description
private
Mode(final int id)

Method Summary

Modifier and TypeMethod and Description
public static Threading.Mode
public static Threading.Mode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

idback to summary
public final int id
MTback to summary
public static final Threading.Mode MT

Full multithreaded OpenGL, i.e. any invoke commands will be issued on the current thread immediately.

ST_AWTback to summary
public static final Threading.Mode ST_AWT

Single-Threaded OpenGL on AWT EDT

ST_WORKERback to summary
public static final Threading.Mode ST_WORKER

Single-Threaded OpenGL on dedicated worker thread.

Constructor Detail

Modeback to summary
private Mode(final int id)

Method Detail

valueOfback to summary
public static Threading.Mode valueOf(String name)
valuesback to summary
public static Threading.Mode[] values()