JOGL: Newt Multiple Threads & Windows

Newt is capable of handling multiple threads and windows.

For best compliance with the underlying OS, one shall create a window,

and handle it’s events within the same thread.

Below you see the invocation of the ES2 RedSquare jogl-demos utilizing multiple threads.

  • Single thread (Unix, Win32)
    java -Djava.awt.headless=true demos.es2.RedSquare -GL2

  • Single thread (MacOSX)
    java -XstartOnFirstThread -Djava.awt.headless=true demos.es2.RedSquare -GL2

  • Multiple threads & windows (Unix, Win32)
    java -Djava.awt.headless=true demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2

  • Multiple threads & windows (Unix, Win32)
    java -XstartOnFirstThread -Djava.awt.headless=true com.sun.javafx.newt.util.MainThread demos.es2.RedSquare -GL2 -GL2 -GL2 -GL2

The serialization of the main Java class through com.sun.javafx.newt.util.MainThread

may be used for all platforms, since it only takes effect on MacOSX.

This allows you an almost platform independent invocation of your multithreaded Java applications.

On MacOSX, com.sun.javafx.newt.util.MainThread will occupy the main thread and
serializes all native window related tasks through it.
This mechanism is thread safe utilizes reentrant locking.