Top Description Fields Constructors Methods
com.jogamp.nativewindow.awt

public Class AppContextInfo

extends Object
Class Inheritance
Imports
java.lang.ref.WeakReference, java.lang.reflect.Method, java.security.AccessController, .PrivilegedAction, com.jogamp.common.util.RunnableTask, jogamp.nativewindow.jawt.JAWTUtil

Instance of this class holds information about a ThreadGroup associated sun.awt.AppContext.

Non intrusive workaround for Bug 983 and Bug 1004, see getCachedThreadGroup().

Field Summary

Modifier and TypeField and Description
private static final boolean
private static final Method
private static final Object
private volatile WeakReference<Object>
private volatile WeakReference<ThreadGroup>

Constructor Summary

AccessConstructor and Description
public
AppContextInfo(final String info)

Method Summary

Modifier and TypeMethod and Description
private static Object
public final ThreadGroup
getCachedThreadGroup()

Returns the ThreadGroup belonging to the last known sun.awt.AppContext as queried via update(String).

public Thread

Returns:

the Thread used to invoke the runnable, which may be the current Thread or a newly created one, see above.
invokeOnAppContextThread
(final boolean
if true, waits until runnable execution is completed, otherwise returns immediately.
waitUntilDone
,
final Runnable
the Runnable to be executed. If waitUntilDone is true, the runnable must exist, i.e. not loop forever.
runnable
,
final String
the base name for the new thread if required. The resulting thread name will have either '-OnAppContextTG' or '-OnSystemTG' appended
threadBaseName
)

Invokes runnable on a Thread belonging to the sun.awt.AppContext ThreadGroup, see getCachedThreadGroup().

public final boolean
isValid()

Returns true if this instance has valid sun.awt.AppContext information, i.e. getCachedThreadGroup() returns not null.

private static String
toHexString(final int i)

public final boolean

Returns:

true if the current ThreadGroup is mapped to an sun.awt.AppContext and the information is good, otherwise false.
update
(final String
informal string for logging purposes
info
)

Update sun.awt.AppContext information for the current ThreadGroup if uninitialized or sun.awt.AppContext changed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUGback to summary
private static final boolean DEBUG
getAppContextMethodback to summary
private static final Method getAppContextMethod
mainThreadAppContextLockback to summary
private static final Object mainThreadAppContextLock
mainThreadAppContextWRback to summary
private volatile WeakReference<Object> mainThreadAppContextWR
mainThreadGroupWRback to summary
private volatile WeakReference<ThreadGroup> mainThreadGroupWR

Constructor Detail

AppContextInfoback to summary
public AppContextInfo(final String info)

Method Detail

fetchAppContextback to summary
private static Object fetchAppContext()
getCachedThreadGroupback to summary
public final ThreadGroup getCachedThreadGroup()

Returns the ThreadGroup belonging to the last known sun.awt.AppContext as queried via update(String).

Returns null if no sun.awt.AppContext has been queried.

The returned ThreadGroup allows users to create a custom thread belonging to it and hence mitigating Bug 983 and Bug 1004.

update(String) should be called from a thread belonging to the desired sun.awt.AppContext, i.e. early from within the special threaded application.

E.g. JAWTWindow issues update(String) in it's constructor.

invokeOnAppContextThreadback to summary
public Thread invokeOnAppContextThread(final boolean waitUntilDone, final Runnable runnable, final String threadBaseName)

Invokes runnable on a Thread belonging to the sun.awt.AppContext ThreadGroup, see getCachedThreadGroup().

update(String) is issued first, which returns true if the current thread belongs to an AppContext ThreadGroup. In this case the runnable is invoked on the current thread, otherwise a new Thread will be started.

If a new Thread is required, the AppContext ThreadGroup is being used if available, otherwise the default system ThreadGroup.

Parameters
waitUntilDone:boolean

if true, waits until runnable execution is completed, otherwise returns immediately.

runnable:Runnable

the Runnable to be executed. If waitUntilDone is true, the runnable must exist, i.e. not loop forever.

threadBaseName:String

the base name for the new thread if required. The resulting thread name will have either '-OnAppContextTG' or '-OnSystemTG' appended

Returns:Thread

the Thread used to invoke the runnable, which may be the current Thread or a newly created one, see above.

isValidback to summary
public final boolean isValid()

Returns true if this instance has valid sun.awt.AppContext information, i.e. getCachedThreadGroup() returns not null.

toHexStringback to summary
private static String toHexString(final int i)
updateback to summary
public final boolean update(final String info)

Update sun.awt.AppContext information for the current ThreadGroup if uninitialized or sun.awt.AppContext changed.

See getCachedThreadGroup() for usage.

Parameters
info:String

informal string for logging purposes

Returns:boolean

true if the current ThreadGroup is mapped to an sun.awt.AppContext and the information is good, otherwise false.