synchronizing in multithreaded application

  • Thread starter Thread starter Law
  • Start date Start date
L

Law

I have the following synchronizing problem below with
multithreaded application. I wonder if you know the
resolution.

I have 3 classes:
1) Product class
2) Buffer class (the name can be changed later)
3) Upload class

Product class is responsible in retrieving product
information from database and store it in the buffer class
(there are thousands of products). Upload class will read
product information from buffer and call XML web service.
When the app is running, the original thread will create
product class and start dumping the data to buffer class.
After a while, it will create the 2nd thread to start
Upload class. The size of buffer will be consistent
because upload class will read the buffer, call web
service and remove the data from the buffer. The original
and 2nd threads are running concurrently until there is no
more product to be put in buffer class and the buffer
class has been emptied by upload class.

- Is thread synchronization necessary in this scenario?
- What is the appropriate design of buffer class?

Thanks for your time.

Law
 
Hi Law,

You could use Queue as buffer class (if queue suites you).
In this case, use Queue.Synchronized(bufferQueue) wrapper to use thread-safe
access.
 
Back
Top