Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

UI Thread Question  RSS feed

 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps this is the wrong forum to be in, but I thought I would start here. I'm running two instances of my application as follows (quick sample):



Within the server code, I printed the thread name and both threads print "AWT Event-0" using Thread.currentThread().getName().

Without dumping all of my code into this window, how or what am I doing wrong?

Thanks for everyones time and feedback.
 
Henry Wong
author
Sheriff
Posts: 22837
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shannon Sims:
Perhaps this is the wrong forum to be in, but I thought I would start here. I'm running two instances of my application.

Within the server code, I printed the thread name and both threads print "AWT Event-0" using Thread.currentThread().getName().

Without dumping all of my code into this window, how or what am I doing wrong?

Thanks for everyones time and feedback.


Depends on what you mean by "within the server code". If this means code that is called from the runnable, then you should get the name that you assigned when the thread is created.

If this is an event listener -- called by the windowing system. Then you should see what you are describing. Event listeners are called from the event dispatching thread which is a different thread.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless your Application constructor contains a while(true) loop that doesn't return, both of the threads you create here exit very quickly; so quickly, in fact, that there's little point in creating them. The only code that runs on either of these threads is the code in the body of the Application constructor, and any code that it calls directly. As soon as an Application object is constructed, run() returns and the Thread exits.
 
Shannon Sims
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry/Ernest,
Thank you very much for replying! Since I do not have access to the Internet at home, I had to wait until this morning to reply.

Henry,
The Application is executing my UI (Swing class), but I am clicking a button which would execute the "event dispatching thread" (as you explained) and yes, therefore, that would make sense why I am not seeing the names of my threads (thread1 and thread2). Thank you for explaining this very clearly!

Ernest,
Within the Application constructor there is not a while loop, the Application constructor only displays my UI. Thanks for further explaining what the threads are doing, it helps me to understand what my next approach needs to be.

Once again, thank you!!!
-Shannon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!