Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / September 2005

Tip: Looking for answers? Try searching our database.

Is this thread the event dispatching thread?

Thread view: 
Stefan Ram - 26 Sep 2005 13:02 GMT
 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, but I believe this was a special purpose call for
 to check whether it is executed within the event dispatching thread.

 Does anyone know of such a method?
Thomas Bühler - 26 Sep 2005 13:29 GMT
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?
Thomas Fritsch - 26 Sep 2005 13:59 GMT
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.

Roedy Green - 26 Sep 2005 22:45 GMT
>  Does anyone know of such a method?

toString()

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.