Re: Help - Timing Logic




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



.



Relevant Pages

  • Re: Help - Timing Logic
    ... are you selecting on the entire contents of a 'message' table and looping through an in-memory dataset... ... You could use the internal locking mechanisms of the database to achieve this ... ... you are essentially 'LOCKING' the entire table until the transaction is over... ... 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... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: One File To Capture All Transactions
    ... I am thinking particularly of the internet situation where there may well be significant delays between disparate systems that could cause the transactions to not wind up in the correct order. ... The problem of locking out an order because of stock availability is a significant issue and I feel that it is more likely to be affected by the people on the floor than the system so it is probably not worth the trouble in many instances. ... What really floored the accountant was that if he had light orders he would drop off the third tanker trailer and replace it with a flat loaded with beer as he knew he would sell that. ... Of course if you really want to argue with an accountant then FIFI, LIFO etc will really get them going and this transaction thing gets interesting. ...
    (comp.databases.pick)
  • Re: Working Transactions somehow started not to work
    ... Transaction and locking are not properties of recordsets but are properties ... Opening a served-based cursor will put a lock on ... SL> and are not associated necessarily with server-based cursors. ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Help - Timing Logic
    ... If you need to implement a locking mechanism / or / logging mechanism / or / a checking mechanism to avoid duplicate messages caused by multi-threading ... ... Is it the READ from the database ... ... Perhaps a stored proc may be faster to execute and return the values as opposed to building the transaction in the code. ... implement as above locking only the records you retrieve / update - need to watch out here for table locking ... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MATREADU/MATWRITE statements timing out
    ... Locking of transaction records (as ... If I take a typical debtor master file I can be ... Pessimistic locks for transactions (required for transaction ...
    (comp.databases.pick)

Quantcast