Top Description Inners Fields Constructors Methods
com.jogamp.newt.util

public Class MainThread

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, .InvocationTargetException, java.util.ArrayList, .List, com.jogamp.nativewindow.NativeWindowFactory, com.jogamp.common.os.Platform, com.jogamp.common.util.InterruptSource, .PropertyAccess, .ReflectionUtil, jogamp.newt.Debug, .NEWTJNILibLoader

NEWT Utility class MainThread

FIXME: Update this documentation! This class just provides a main-thread utility, forking of a main java class on another thread while being able to continue doing platform specific things on the main-thread. The latter is essential for eg. MacOSX, where we continue to run NSApp.run().

This class provides a startup singleton main thread, from which a new thread with the users main class is launched.
Such behavior is necessary for native windowing toolkits, where the windowing management must happen on the so called main thread e.g. for Mac OS X !
Utilizing this class as a launchpad, now you are able to use a NEWT multithreaded application with window handling within the different threads, even on these restricted platforms.
To support your NEWT Window platform, you have to pass your main thread actions to invoke(..), have a look at the NEWT Mac OSX Window driver implementation

Todo

Some hardcoded dependencies exist in this implementation, where you have to patch this code or factor it out.

If your platform is not Mac OS X, but you want to test your code without modifying this class, you have to set the system property newt.MainThread.force to true.

The code is compatible with all other platform, which support multithreaded windowing handling. Since those platforms won't trigger the main thread serialization, the main method will be simply executed, in case you haven't set newt.MainThread.force to true.

Test case on Mac OS X (or any other platform):

   java -XstartOnFirstThread com.jogamp.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2
Which starts 4 threads, each with a window and OpenGL rendering.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
protected static final boolean
public static final boolean
HINT_USE_MAIN_THREAD

if true, use the main thread EDT, otherwise AWT's EDT

private static final boolean
private static final String
private static MainThread.UserApp
private static final Platform.OSType
private static final ThreadGroup
private static final MainThread
public static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static final Thread[]
getAllThreads(final int[] count)

private static final int
getNonDaemonThreadCount(final List<Thread> ignoreThreads)

private static final List<Thread>
private static final ThreadGroup
public static MainThread
public static void
main(final String[] args)

Your new java application main entry, which pipelines your application

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUGback to summary
protected static final boolean DEBUG
HINT_USE_MAIN_THREADback to summary
public static final boolean HINT_USE_MAIN_THREAD

if true, use the main thread EDT, otherwise AWT's EDT

isMacOSXback to summary
private static final boolean isMacOSX
MACOSXDisplayClassNameback to summary
private static final String MACOSXDisplayClassName
mainActionback to summary
private static MainThread.UserApp mainAction
osTypeback to summary
private static final Platform.OSType osType
rootThreadGroupback to summary
private static final ThreadGroup rootThreadGroup
singletonMainThreadback to summary
private static final MainThread singletonMainThread
useMainThreadback to summary
public static boolean useMainThread

Constructor Detail

MainThreadback to summary
public MainThread()

Method Detail

getAllThreadsback to summary
private static final Thread[] getAllThreads(final int[] count)
getNonDaemonThreadCountback to summary
private static final int getNonDaemonThreadCount(final List<Thread> ignoreThreads)
getNonDaemonThreadsback to summary
private static final List<Thread> getNonDaemonThreads()
getRootThreadGroupback to summary
private static final ThreadGroup getRootThreadGroup()
getSingletonback to summary
public static MainThread getSingleton()
mainback to summary
public static void main(final String[] args) throws SecurityException, NoSuchMethodException, ClassNotFoundException

Your new java application main entry, which pipelines your application

com.jogamp.newt.util back to summary

pack-priv Class MainThread.UserApp

extends Thread
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String[]
private final Method
private final String
private final String
private List<Thread>

Constructor Summary

AccessConstructor and Description
public
UserApp(final String mainClassName, final String[] mainClassArgs)

Method Summary

Modifier and TypeMethod and Description
public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.
Inherited from com.jogamp.common.util.InterruptSource.Thread:
clearInterruptSourcecreategetInterruptCountergetInterruptSourceinterrupt

Field Detail

mainClassArgsback to summary
private final String[] mainClassArgs
mainClassMainback to summary
private final Method mainClassMain
mainClassNameback to summary
private final String mainClassName
mainClassNameShortback to summary
private final String mainClassNameShort
nonDaemonThreadsAtStartback to summary
private List<Thread> nonDaemonThreadsAtStart

Constructor Detail

UserAppback to summary
public UserApp(final String mainClassName, final String[] mainClassArgs) throws SecurityException, NoSuchMethodException, ClassNotFoundException

Method Detail

runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override