Thread Synchronization
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Priti_Rajeshwari
Posted On:   Friday, February 15, 2002 10:14 PM

I have developed a GUI on invoking which a thread is spawned at the backround. This thread collects some data and stores it in an object. I do not want the UI to display this data till thread completes its work. Can any Jgurus help me with a soln to the problem defined above.

Re: Thread Synchronization

Posted By:   Luigi_Viggiano  
Posted On:   Saturday, February 16, 2002 06:53 AM

Make a thread entrusted to write data to the UI (let's call it UIWriterThread class), but with a while statement like this:
  
while (true) {
wait();
sendDataToTheGUI();
}

The background thread collecting data will then notify the UIWriterThread with a code like this:

data = getDataFromDB();
uiWriterThread.setData(data);
uiWriterThread.notify();

it should work.
About | Sitemap | Contact