Hello,
Our FAQ page goes into some detail on this...
http://www.melissadata.com/tech/aobjectfaq.htm2.7.1 What is multi-threaded programming, with respect to MelissaDATA’s data quality tools?
When working with MelissaDATA API components, you are multi-threading in these situations:
• You have several threads, each creating an instance of an object.
• You have several threads, all using a single (or a few) instances of an object.
Be aware that sometimes you are multi-threading without even realizing it. This is particularly true for web applications. For example, a web service will often handle multiple requests simultaneously. Each request will be handled on a separate thread, though the code you have written to handle a request is oblivious to this.
2.7.2 What should be my primary concerns?
Primarily, the thread that creates an instance to an object ‘owns’ that instance and any other threads should not use that instance.
If you choose to violate this rule and ‘share’ instances across threads, your program must ensure that a thread is completely done using the instance before another thread attempts to use it. Often, this is done through the use of critical sections, mutexes or semaphores.
Bear in mind that it is very difficult to debug multi-threaded applications, and the precautions needed to share instances further complicate the issue.
The more practical solution is to ensure that each thread owns its own instance. However, when working with large numbers of threads, this can be problematic, as operating system limitations (open threads, file handles, memory, etc) can be a limiting factor.
2.7.3 Why is threading an issue?
At any given moment, an instance exists at a certain state. Two threads calling the same instance will usually cause the instance to change states in unexpected ways, leading to incorrect results and/or crashes.
For example, say thread 1 calls the Address Object (AO) with an address. The AO at this point is in ‘State A’. Then, before thread 1 can obtain the AO’s results, thread 2 calls the AO with a different address, putting it into ‘State B’. When thread 1 retrieves its results, it will retrieve the ‘State B’ results rather than the correct ‘State A’ results.
2.7.4 Can MelissaDATA’s API components detect improper thread usage and handle the situation accordingly?
No, they cannot. It is not a fault of the programming, but rather is inherent to the way microprocessors and operating systems are designed and used.