简体   繁体   English

Hibernate与akka演员合作吗?

[英]does Hibernate work with akka actor?

my main concern is on ThreadLocal . 我主要关心的是ThreadLocal akka actors don't bind to specific thread, so any use of thread local storage will be problematic on akka actors akka actors不绑定到特定的线程,因此任何使用线程本地存储都会对akka actor产生问题

does Hibernate use ThreadLocal ? Hibernate使用ThreadLocal吗?

can they coexist in this case? 他们可以在这种情况下共存吗?

Yes. 是。 I use Hibernate (via the JPA interface) together with Akka actors. 我使用Hibernate(通过JPA接口)和Akka actor。

I have two approaches to deal with multi-threading: 我有两种方法来处理多线程:

  1. If each actor updates information that cannot conflict with other actors (for example, each row in a table will never be used by multiple actors), you can create a single entity manager per actor and use that for the life of the actor. 如果每个actor更新的信息不会与其他actor发生冲突(例如,表中的每一行永远不会被多个actor使用),则可以为每个actor创建一个实体管理器,并将其用于actor的生命周期。 Although, if a transaction fails it may be best to discard the entity manager. 但是,如果事务失败,最好丢弃实体管理器。
  2. Otherwise, in each invocation of the actor (via it's receive function) that needs database access, create a new entity manager, begin a transaction, access the database, commit the transaction, and then close the entity manager. 否则,在每次调用需要数据库访问的actor(通过它的接收函数)时,创建一个新的实体管理器,开始一个事务,访问数据库,提交事务,然后关闭实体管理器。

I have the first approach running in production systems. 我有第一种方法在生产系统中运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM