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

3 views (last 30 days)
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)

Accepted Answer

Mohammad Sami
Mohammad Sami on 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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!