Most times a Java class calls a Haxe function, it does so on the UI thread, which can lead to thread-related errors. These errors can be avoided by switching back to the main thread before executing any code.
Usage:
class MyClass implements JNISafety
{
@:runOnMainThread
public function callbackFunction(data:Dynamic):Void
{
// Code here is guaranteed to run on Haxe's main thread. It's safe
// to call `callbackFunction` via JNI.
}
public function notACallbackFunction():Void
{
// Code here will run on whichever thread calls the function. It may
// not be safe to call `notACallbackFunction` via JNI.
}
}