SwingUtilities.isEventDispatchThread()
Best regards
Thomas
> I believe having read in a newsgroup recently a special call
> to find out if it is executed within the event dispatching thread.
[quoted text clipped - 3 lines]
>
> Does anyone know of such a method?
Stefan Ram schrieb:
> I believe having read in a newsgroup recently a special call
> to find out if it is executed within the event dispatching thread.
> I would know how to get and inspect the name of the current
> thread,
To get the name of the current thread:
String name = Thread.currentThread().getName();
> but I believe this was a special purpose call for
> to check whether it is executed within the event dispatching thread.
To ask whether the current thread is the EDT:
boolean b = SwingUtilities.isEventDispatchThread();
> Does anyone know of such a method?
BTW: Things like these can easily be found in the API doc.

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Stefan Ram - 26 Sep 2005 14:31 GMT
>boolean b = SwingUtilities.isEventDispatchThread();
Thanks for the answers!
>BTW: Things like these can easily be found in the API doc.
If you do not already know that it belongs to the class
"SwingUtilities" and that it is named like
"isEventDispatchThread", how would you search for it in the
API doc?
Thomas Fritsch - 26 Sep 2005 15:06 GMT
Stefan Ram schrieb:
>>BTW: Things like these can easily be found in the API doc.
>
> If you do not already know that it belongs to the class
> "SwingUtilities" and that it is named like
> "isEventDispatchThread", how would you search for it in the
> API doc?
Good question!
Let us assume you only know that the method returns a boolean
(indicating whether the current thread is the event dispatch thread).
There is a general covention that methods taking no parameters and
returning boolean should have a name starting with "is".
With this knowlwdge go to <http://java.sun.com/j2se/1.5.0/docs/api/>.
Click "Index" at the very top, click "I", scroll down to the methods
"is...", start browsing there, find the line
"isEventDispatchThread() - Static method in class
javax.swing.SwingUtilities". Voila.
BTW: you just learnt to appreciate name conventions. ;-)

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
Roedy Green - 26 Sep 2005 22:59 GMT
>There is a general covention that methods taking no parameters and
>returning boolean should have a name starting with "is".
If you forget how to look up packages, classes or methods, you can
always use the "all packages", "all classes" or "all methods" entries
in the Java glossary to point you to the sun site or to your local
copy of the docs.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Thomas Hawtin - 26 Sep 2005 21:02 GMT
>>boolean b = SwingUtilities.isEventDispatchThread();
>
[quoted text clipped - 6 lines]
> "isEventDispatchThread", how would you search for it in the
> API doc?
It's under I in the index. :) Or you could use grep -R (or a grep like
utility) on the JavaDocs or source code.
java.awt.EventQueue.isDispatchThread is a more direct, and less
arbitrarily placed, equivalent.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Roedy Green - 26 Sep 2005 23:13 GMT
>java.awt.EventQueue.isDispatchThread
if you forget this, it is documented under thread in the java glossary
at http://mindprod.com/jgloss/thread.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
> Does anyone know of such a method?
toString()

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.