01-30-2012 10:01 AM
Is it possible to multi thread document inserts using the Unity Api. My understanding of Unity is you can send multi -threaded inserts requests to the API, but the API itself will queue up the inserts, and perform a Insert one at a time (Single Threaded). Could this be resolved with more than one Unity API license?
02-06-2012 10:57 AM
Hi Paul,
We do something similar with the API by simultaneously using multiple licenses, and use a multi-threaded Producer/Consumer architecture to assign tasks to threads. Basically, in C#, you should be able to create a queue of connections:
Queue<Application> connQueue = new Queue();
...add n open connections to queue, and use a semaphore to keep track of connections in use:
Semaphore semConn = new Semaphore(n, n);
Then, create a queue of documents to add:
Queue<SomeTypeToHoldDocumentInfo> objDocData = new Queue();
... Add a bunch of objects to the queue that contain the info needed to create new documents...
and loop through:
while(objDocData.Count > 0) {
semConn.WaitOne();
Application objApp = connQueue.Dequeue();
var curDocData = objDocData.Dequeue();
// Create a simple type first called ThreadParamInfo that has two properties, one for the connection and one for the doc data
ThreadParamInfo appInfo = new { App = objApp, Data = curDocData};
Thread objAddDocThread = new Thread(new ParameterizedThreadStart( paramInfo => {
try {
... code to create NewDocumentProperties and store the document with the paramInfo.App parameter being your connection to OnBase, and paramInfo.Data being the doc data...
} finally {
// Add connection back to queue
connQueue.Enqueue(appInfo);
semmConn.Relase();
}
});
objAddDocThread.Start(objApp);
}
... Join threads and clean up all connections...
NB, this is just pseudo-code and I assumed that you're familiar with .Net multi-threading semantics. It's also important to ensure that connections are properly released on AppDomain exit in case of errors in the main thread or other really bad unrecoverable errors, and that all threads are joined and complete before the code terminates.
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.