How do I prove that javaObjectEDT and javaMethodEDT are indeed being run on EDT?

1 visualizzazione (ultimi 30 giorni)
I'm developing a MATLAB-generated Java Package that is to be used in a Java GUI. I want to be sure that when I interact with Swing components, it's being done on the EDT. However, the documentation for javaObjectEDT and javaMethodEDT is pretty sparse. When I run the following code, it tells me that the current thread is 'main' instead of 'AWT-EventQueue-0' like I expect. Am I using this incorrectly? How do I ensure that Java objects and methods are being run on the EDT?
import java.lang.Thread
javaMethodEDT('getName',Thread.currentThread)

Risposta accettata

Mohammad Sami
Mohammad Sami il 8 Apr 2021
Your invocation of Thread.currentThread is executed in the matlab main thread not on EDT.
Do as follows.
t = javaMethodEDT('currentThread','java.lang.Thread');
t.getName
%ans =
%AWT-EventQueue-0
You can read this answer for more details.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by