OCCI createEnvironment 阻止我的线程
我正在编写一个多线程应用程序,其中有一个主线程将任务分配给工作线程。根据任务,工作线程使用全局 occi 环境创建连接。当工作线程完成其任务时,它会关闭连接(我确信,终止时不会抛出异常)。
我的问题是,一段时间后(有时 5 分钟,有时 5 小时),线程无法从环境中获得连接,并且它们被阻塞在那里。
可能是什么问题?
I'm writing a multi-threaded application, where there is a main thread which distributes tasks to the worker threads. According to the task, a worker thread creates a connection, by using a global occi environment. When a worker thread completes its task, it closes the connection (I'm sure, there is no exception thrown while termination).
My problem is that after a while(sometimes 5 mins, sometimes 5 hours) the threads cannot get connection from the environment, and they get blocked there.
What can be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我没有正确识别问题。我以为线程被阻塞了,但实际上它们没有,它们只是意外地退出了:)。问题解决了。
I guess I didn't identify the problem correctly. I thought the threads get blocked, but actually they didn't, they simply exited there unexpectedly :). Problem solved.
您是否考虑过使用线程池?这样您就不需要在每次工作完成时关闭连接。
我认为设置/关闭数据库连接也相当昂贵。
Have you considered using a thread pool? Then you don't need to close the connection every time the work is done.
Setting up/closing the database connection is also quite expensive, i think.