Server Threading

Sep 2, 2015 at 10:07 PM
I have a server where I have multiple services with each reading/writing data in a transaction. I initialize the engine one time and the instance is passed to each service to create transactions. Is this the proper way?
Sep 3, 2015 at 8:34 AM
Edited Sep 3, 2015 at 8:36 AM
If I understand you correctly - every your service is a separate OS process. If so - then usage is wrong. One DBreeze database can be used only with one OS process. Database files will be locked and DBreeze instances in other processes will not be able to work with them. But inside of one OS process many managed threads can share one DBreeze instance via transaction mechanism.

Every OS process can use its one DBreeze database. DBreeze must be instantiated only once per process per database (it's possible to have many databases in one process).
Sep 3, 2015 at 1:42 PM
It is just a multi-threaded server accepting requests. When the server starts, one engine is created.
As a request is processed, I pass the engine to the thread handling the request and it creates the transaction from the engine.
There will be multiple threads running simultaneously. There are not separate OS processes accessing the same database.

I just want to make sure that the call Engine.GetTransaction() is safe to call from multiple threads with the single engine.

And I want to say that I'm very impressed with the whole product. It is precise, simple, elegant, and best of all, it just works!
Sep 3, 2015 at 2:05 PM
Thanks for the warm words!


var tran = Engine.GetTransaction(); can live only in one thread, but you can in parallel in many different threads create many transactions.

This should be OK
var DBreezeEngine; //let'S assume instantiated
void main()
{
Task.Run(()=>
{
    using(var tran=DBreezeEngine.GetTransaction())
    {
         tran.SynchronizeTables("t1","t2");
         tran.Insert<int,int>("t1",1,1);
         tran.Insert<int,int>("t2",2,1);
         tran.Commit();
     }
});

Task.Run(()=>
{
    using(var tran=DBreezeEngine.GetTransaction())
    {
         tran.SynchronizeTables("t1","t2");
         tran.Insert<int,int>("t1",3,1);
         tran.Insert<int,int>("t2",4,1);
         tran.Commit();
     }
});

}
but to give instantiated tran from one thread to another thread is not allowed.