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

3 vues (au cours des 30 derniers jours)
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)

Réponse acceptée

Mohammad Sami
Mohammad Sami le 8 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Call Java from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by