Communication between threads

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.
brianw13aAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brianw13aAuthor Commented:
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
CEHJCommented:
Difficult to get a single link, but there's a similar question that's been asked recently - i'll try to find it ...
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

brianw13aAuthor Commented:
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
CEHJCommented:
Sure
0
brianw13aAuthor Commented:
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
objectsCommented:
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
CEHJCommented:
>>It appears that the newly created thread is doing all the work without even utilizing the listener

Where do you mean exactly?
0
brianw13aAuthor Commented:
The previous experts post that you have refered to
0
brianw13aAuthor Commented:
Worked great!
0
CEHJCommented:
8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.