Spring MongoDB进程/线程泄漏 [英] Spring MongoDB process/thread leaking

查看:46
本文介绍了Spring MongoDB进程/线程泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 tomcat7 上运行的 Spring3 网络应用程序.http://www.mkyong.com/mongodb/spring-data-mongodb-hello-world-example/,我遵循了本教程,然后我有一个每 10 秒运行一次的 @Scheduled 方法.在这个方法中,它打开一个与 MongoOperations 的 mongo 连接 mongoOperation = (MongoOperations)ctx.getBean("mongoTemplate");

I have a Spring3 web-app running on tomcat7. http://www.mkyong.com/mongodb/spring-data-mongodb-hello-world-example/, I have followed this tutorial and then I have a @Scheduled method that runs every ten second. In this method it opens a mongo connection with MongoOperations mongoOperation = (MongoOperations)ctx.getBean("mongoTemplate");

我现在的问题是我不知道如何关闭连接,每十秒就会在 tomcat 中产生一个新的进程/线程......所以我想你可以想象这个问题.有没有人知道如何解决这个问题?

My problem now is that I dont know how to close the connections and every ten second a new process/thread is spawned in tomcat.. so I think you can imagine the problem. Does anyone have any idea how to solve this?

推荐答案

解决方法是将 MongoOperations 替换为实现 MongoTemplate,然后在 MongoTemplate 上调用 mongoTemplate.getDb().getMongo().close();

Solved by replacing MongoOperations with the implementation MongoTemplate and then on the MongoTemplate call mongoTemplate.getDb().getMongo().close();

这篇关于Spring MongoDB进程/线程泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆