Re: Help - Timing Logic
- From: "jeff" <jhersey at allnorth dottt com>
- Date: Tue, 28 Nov 2006 07:21:52 -0800
Question:
What is the reason for the 4 threads?
Do you need all these threads processing the same dataset?
Just asking, maybe you could change your approach to avoid this problem...
If not, investigate Record Locking / Transactions...
How are you retrieving your records in to memory for processing ...
ie,
- are you selecting on the entire contents of a 'message' table and looping
through an in-memory dataset...
- do you retrieve 'chunks' or rows from the message table based on
parameters...
You could use the internal locking mechanisms of the database to achieve
this ... but procede with caution...
Start Transaction...
SELECT * FROM MESSAGE TABLE
....
stuff this into a data table on the desktop
....
DELETE * FROM MESSAGE TABLE
....
punt / clean the table.
....
End Transaction.
The transactions places locks on the table ... but selecting the entire
tables contents ... you are essentially 'LOCKING' the entire table until the
transaction is over...
So, each thread's 'retrieve' process will have to wait in line until the
select and delete are processed. As well, anything triggering 'New Messages
to be Added' will be delayed until the Transaction is completed...
You may impact the overall performance of you application ... need to
investigate.
If locking does not work for you, you will need to implement some type of
logging / checking approach...
ie... have a log table...once a process has sent the message, write to a log
table ... message sent. Before each message is compiled and sent, check the
log table to see if another process has sent the message...if not, send you
message...
A snip of code would be great to figure out how you are retrieving a list of
messages and how you are processing each record...
Jeff.
"Jay" <someone@xxxxxxxxxxxxx> wrote in message
news:O2phzwvEHHA.4280@xxxxxxxxxxxxxxxxxxxxxxx
I have a multi threaded VB.NET application (4 threads) that I use to send
text messages to many, many employees via system.timer at a 5 second
interval. Basically, I look in a SQL table (queue) to determine who needs
to receive the text message then send the message to the address. Only
problem is, the employee may receive up to 4 of the same messages because
each thread gets the recors then sends the message. I need somehow to
prevent this... just can't think of how. Somehow I need the other threads
to know that another thread is already using that record and move on to the
next record. I thought of getting the record then marking it (column
value) as in use and writing the code to look for records only where not in
use... problem is all 4 run fast enough to all use/mark the row. Any
thoughts?
Thanks a lot.
Jay
.
- Follow-Ups:
- Re: Help - Timing Logic
- From: Jay
- Re: Help - Timing Logic
- References:
- Help - Timing Logic
- From: Jay
- Help - Timing Logic
- Prev by Date: Re: How broad should an interface be? Advice needed.
- Next by Date: communicate with Activesync? Can it be done?
- Previous by thread: Re: Help - Timing Logic
- Next by thread: Re: Help - Timing Logic
- Index(es):
Relevant Pages
|