473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1326
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: chahnaz.ourzikene | last post by:
Hi all, This is the first i post in this newsgroup, i hope my english is not too bad... Let's get straight to the point ! I have a little probleme using threads in my little training example :...
5
by: Sinan Nalkaya | last post by:
hello, i need a function like that, wait 5 seconds: (during wait) do the function but function waits for keyboard input so if you dont enter any it waits forever. i tried time.sleep() but when...
10
by: HK | last post by:
With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need to take a recordset (e.g. 100,000 records) and spawn a thread to handle an internet XML transaction routine for each of the...
0
by: hynek.cihlar | last post by:
A strange behaviour thatI found in ASP.NET 2.0. I am trying to issue a callback request (handled by ICallbackEventHandler and RaiseCallbackEvent) and a regular GET request in the client browser...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
3
by: Ronald S. Cook | last post by:
In my Win app, I'm needing to load a media file into my Windows Media Player control, and THEN read an attribute from the file. The thing is, the file has to be playing for a split second before...
5
by: bean330 | last post by:
Hey, I'm somewhat new to C# and I need a little help, please! I'm selecting a bunch of records, setting properties on a COM executable and then calling a method on that executable to run. I...
0
by: Ling | last post by:
I am using boost.python to wrap C++ function which includes directmusic libraries to simply play the midi, but lots of linkage errors "error LNK2001: unresolved external symbol". I wonder if it is...
3
by: dedalusenator | last post by:
Hello Folks, My first posting here and I am a stuck in figuring out the exact way to update a global variable from within a function that doesnt return any value (because the function is a...
3
by: Michael Schöller | last post by:
Hello, First of all english is not my natural language so please fogive me some bad mistakes in gramatic and use of some vocables :). I have a great problem here. Well I will not use it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.