Need help with threading

  • Thread starter Thread starter Benjamin Walling
  • Start date Start date
B

Benjamin Walling

We have 109 remote offices all running Sybase ASA Server. We collect data
from these offices and consolidate it into our main server. I have written
a program that will read from each office and synchronize the data. It
takes a while to run because each office only has a 128k Frame Relay.

I have two database classes: one for accessing the office, one for accessing
the main server. The database classes expose simple functions of
connecting, updating and reading from the databases.

I have a class that operates the synchronization - imports tables in the
correct order and performs various checks on the data.

I have a program that calls the synchronization class sequentially for each
office.

It takes about 2 minutes per office, or about three hours to complete. I'd
like to run this program hourly, so I want to get the total run time down.

I've tried changing the program that calls the synchronization class to
start five threads, and keep five running. The problem I run into is that
the office database class appears to get shared between threads - I get the
same results back from what should be separate offices running in separate
threads.

How can I set it up so that each thread is entirely separate from the other
threads, including any support classes called by those threads?
 
I would say, create the "office" database class within the newly started
thread, and make sure there is no
"Public Shared" variables or properties in that class.

Regards
Fredrik Melin
 
That was the first thing I tried. There are no shared variables or
functions. Everything is private with the exception of the constructors.
 
Ah. Scratch that. I had made some shared functions. Seems to have
eliminated the problem. This had been driving me nuts!
 
Okay, I'm still going nuts.

I have a piece of data in the remote office that is an identifier for that
office. I can compare it to what I have in the central database.

I put a little block of code (using GetScalar) to check this each time
before I get a data reader. It checks correctly each time, however the data
in the reader still comes back from other offices. If I change the check
routine to use a data reader, it returns the incorrect office.

What is going on? Is the OLEDB DataReader object just unsafe in threads?
What should I do to get around this?
 
Hi again.

As far as I know, SQLDataReader is not thread safe, use DataSet's instead.

Regards
Fredrik Melin
 
I started to change my code to use DataSet, but don't you need Connection &
Command objects to fill the dataset? Neither the Connection nor the Command
objects are thread safe.

Is there a thread safe way to get the data? (I have to use the OLEDB.*
objects in order to use the ASA Provider.)
 
Back
Top