Best NHibernate multithreading pattern? -
As we know, the NHibernate session threads are not secure. But many of our long-running threads have a code path partition, all use the loaded objects in the initial thread. } There will be one session for each thread, but this will require the original object to reload each, in addition to this, the final method Is also making changes to the children and will run in a stale object exposition, if there was a change in the other session, or it had to be ejected / reloaded. All threads should use the same session What is the best way to do this? Save the queue in the initial thread (thread secure implementation), which is voted in the missing (instead of EndInvoke ()) from the main thread. Child threads can be included in the NHibernate object to be saved by the main thread. Use some callback mechanism to save / flush objects in the main thread. Is there anything similar to UI Thread Callback in WPF, Control.Invoke () or BackgroundWorker? Save / flush access to lock (session) blocks? It may be dangerous, because modifying the NHibernate object can change the session, even if no saving () / flush () is doing. Do I load and reload the database overhead in the main thread in the main thread for each session, for different sessions, and then it changes again ? [Edit: Poor "solution" due to the risk of object sensitization / stale objects] Also consider that the application has a business logic level above NHibernate, but NHibernate sends his property value on his own Save () command on objects, then only modifying them is NHibernate Save () / Flush () promptly. Edit: It is important that NHibernate objects can change session - lazy loading, chilren collection changes under certain conditions. Therefore it is really better to have a business object layer at the top, which synchronizes all access to NHibernate objects, while keeping the database operation in mind, there is only the minimum time of thread (mainly the offer status setting), and most of the calculations, Monitoring, Web service access and similar, performance loss by data layer synchronization is negligible. First of all, if I understand correctly, different threads can update the same object Are there. In that case, En Hibernate or not, you are making concurrent updates on the same object, which can have unexpected results. Now, to handle the same flow, there may be only one thread to read the same data (but writing different data), I suggest using different sessions - a copy Thread and usage;
You can make some changes to your design to ensure that the object can only be updated (most) one thread.
The second level is placed at the cache sessionforest (rather than the
session ), and therefore all sessions are shared by examples
Comments
Post a Comment