【发布时间】:2012-11-06 13:27:54
【问题描述】:
我有一个带有线程静态会话的多线程应用程序,它对文件执行一些工作。它使用 NH 从服务中消费并在 oracle db 上运行,到目前为止一切顺利。
每个线程都有一个详细的日志,使用无状态会话更轻量级。顺便说一句,当处理某些文件时,我可以看到在 oracle 中管理大量游标以进行日志会话。
例如日志:
- 324 SPC_LOG
- 310 SPC_LOG
- 121 SPC_LOG
和应用程序本身:
- 31 SPC_PRODUCTION_LINE_TEST
- 27 SPC_PRODUCTION_LINE_TEST
- 21 SPC_PRODUCTION_LINE_TEST
这让我用完了 Oracle 游标 ORA-01000。
有人知道是什么原因造成的吗?游标与插入有关还是仅与更新有关?我想每个线程在它生命的尽头都会关闭所有会话,常规的和无状态的。
仅供参考,我是这样写日志的:
-
在会话工厂中
public IStatelessSession GetUserStatelessContext(ConnectionStringSettings connection) { lock (Padlock) { string key = GetConnectionKey(connection); if (StatelessSessions == null) { StatelessSessions = new Dictionary<string, IStatelessSession>(); } if (!StatelessSessions.ContainsKey(key)) { StatelessSessions.Add(key, Factories[connection.ConnectionString].OpenStatelessSession()); } return StatelessSessions[key]; } } -
并写入日志:
using (ITransaction tx = this.LogProcessErrorRepository.BeginTransaction()) { this.LogProcessErrorRepository.Add(log); if (log.Informations != null) { foreach (AdditionalInformation info in log.Informations) { info.Text = this.OracleCLOBHack(info.Text); this.AdditionalInformationRepository.Add(info); } } tx.Commit(); }
【问题讨论】:
-
猜测:尝试使用 ConcurrentDictionary 和 TryGetValue 代替 Dictionary。 msdn.microsoft.com/en-us/library/dd287191.aspx, stackoverflow.com/questions/1949131/…
-
@jamie-ide 据我所知不是并发列表相关的问题,我使用锁来避免并发问题。更多的是与 Oracle 驱动程序、数据库或 NH 行为有关的东西。
标签: c# oracle nhibernate cursor