Check if code is running in main application thread

jmonkey spawns a thread for its main loop. This thread is used for processing events pulled in taskqueue by enqueue method in application class. How can I check if code is running in the thread?



If you’d like to take analogue with swing, enqueue is like a swing SwingUtilities.invokeLater. Something like SwingUtilities.isEventDispatchThread - is what I’m searching for.

I do this:

[java]

MainApp:

private Thread thread;



public void simpleInitApp() {

thread = Thread.currentThread();



}



public boolean isOgl() {

return Thread.currentThread() == thread;

}

[/java]

Then I just check myApp.isOgl()

1 Like

So there is no way to acquire thread information from the jmonkey context, is it?

Uh… That would be in simpleInit instead of main(), right @Sploreg?

@ayvango said:
So there is no way to acquire thread information from the jmonkey context, is it?

Well jme uses a few threadlocal vars but if you need to check on what thread you are it sounds like the approch might not be ideal. Normally you would do things on the update loop via controls or appstates so you'd know when you are on that thread.

oh yea sorry, cut the wrong piece of code (I edited it above).



I actually don’t use it anymore, I do it all through controls now.