?
Solved

Communication between threads

Posted on 2004-11-08
12
Medium Priority
?
187 Views
Last Modified: 2010-03-31
Hello all,

I have just started a project that has me utilizing threads for the first time.  For the most part, everything seems to be working however I am at a crossroads and could use some advice.

I'll try to describe what is happening as best I can.  The app is a user interface that shows representation from hardware in the field (so far PLC values).  I order to obtain these values I must continously poll the devices as there are no message events.  The UI must always be accessible (no noticable delays) and has to 'read' and 'write' values out to the field devices.

So far I have a class that extends Thread and it seems to be working well.  I have started on the UI portion and it doesn't look like that will be a problem either.

I figure that the UI could dump requested device writes into a Hashtable and the device object could read the hashtable for requests before the next poll.

The problem that I have is in getting data changes from the device object to the UI.  I could really use a nudge in the right direction as I don't want to slow the polling down for UI updates.

Please only answer if you have threading experience and thank you in advance.
0
Comment
Question by:brianw13a
  • 6
  • 5
12 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 375 total points
ID: 12524080
You need to ensure that the changes to your ui are made on the event dispatch thread. You could get your app threads to call back the ui (which could implement a Listener pattern) or have your ui updates on a timer. In each case use EventQueue.invokeLater to do the updating
0
 

Author Comment

by:brianw13a
ID: 12524383
CEHJ,

This looks like a winner however a lot of it is over my head.  Do you know of a link that explains how it all works?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12524440
Difficult to get a single link, but there's a similar question that's been asked recently - i'll try to find it ...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 12524475
0
 

Author Comment

by:brianw13a
ID: 12524805
I think I've got it and will give it a try.  I did find another link that I found useful in addition to the one you have supplied.  Just in case someone else asks:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

I'll let you know what happens and thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12524831
Sure
0
 

Author Comment

by:brianw13a
ID: 12525507
I've been reviewing the articles and the prvious discussion and I was wondering if we even need listeners.  It appears that the newly created thread is doing all the work without even utilizing the listener.  Am I correct or out to lunch?

Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 12528962
there are some examples of using the SwingWorker here:

http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html

Instead of listeners, you subclass it and overide the appropriate method(s) to hook in your app code.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12529115
>>It appears that the newly created thread is doing all the work without even utilizing the listener

Where do you mean exactly?
0
 

Author Comment

by:brianw13a
ID: 12529840
The previous experts post that you have refered to
0
 

Author Comment

by:brianw13a
ID: 12535325
Worked great!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12537708
8-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question