468,786 Members | 1,741 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,786 developers. It's quick & easy.

Need help with threading

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?
Nov 20 '05 #1
6 1172
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

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?

Nov 20 '05 #2
That was the first thing I tried. There are no shared variables or
functions. Everything is private with the exception of the constructors.
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:B5********************@giganews.com...
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

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?


Nov 20 '05 #3
Ah. Scratch that. I had made some shared functions. Seems to have
eliminated the problem. This had been driving me nuts!
"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:uR*************@TK2MSFTNGP11.phx.gbl...
That was the first thing I tried. There are no shared variables or
functions. Everything is private with the exception of the constructors.
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:B5********************@giganews.com...
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

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?



Nov 20 '05 #4
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?

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Ah. Scratch that. I had made some shared functions. Seems to have
eliminated the problem. This had been driving me nuts!
"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:uR*************@TK2MSFTNGP11.phx.gbl...
That was the first thing I tried. There are no shared variables or
functions. Everything is private with the exception of the constructors.


"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message news:B5********************@giganews.com...
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

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> 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?
>
>



Nov 20 '05 #5
Hi again.

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

Regards
Fredrik Melin

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:e%****************@TK2MSFTNGP11.phx.gbl...
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?

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Ah. Scratch that. I had made some shared functions. Seems to have
eliminated the problem. This had been driving me nuts!
"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:uR*************@TK2MSFTNGP11.phx.gbl...
That was the first thing I tried. There are no shared variables or
functions. Everything is private with the exception of the constructors.

"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message news:B5********************@giganews.com...
> 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
>
> "Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message > news:%2****************@TK2MSFTNGP09.phx.gbl...
> > 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?
> >
> >
>
>



Nov 20 '05 #6
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.)

"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:Po********************@giganews.com...
Hi again.

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

Regards
Fredrik Melin

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:e%****************@TK2MSFTNGP11.phx.gbl...
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?

"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Ah. Scratch that. I had made some shared functions. Seems to have
eliminated the problem. This had been driving me nuts!
"Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message
news:uR*************@TK2MSFTNGP11.phx.gbl...
> That was the first thing I tried. There are no shared variables or
> functions. Everything is private with the exception of the

constructors.
>
>
> "Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in

message
> news:B5********************@giganews.com...
> > 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
> >
> > "Benjamin Walling" <bw******@latnedtsaoc-reverse.com> wrote in message > > news:%2****************@TK2MSFTNGP09.phx.gbl...
> > > 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?
> > >
> > >
> >
> >
>
>



Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by chahnaz.ourzikene | last post: by
5 posts views Thread by Sinan Nalkaya | last post: by
reply views Thread by hynek.cihlar | last post: by
3 posts views Thread by Ronald S. Cook | last post: by
5 posts views Thread by bean330 | last post: by
reply views Thread by Ling | last post: by
3 posts views Thread by dedalusenator | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.