spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Ram always rises and only stops rising after running out of request. Then it doesn't automatically decrease

Open hoanghunguet opened this issue 10 years ago • 1 comments

I have Spring boot project.When i build project .Ram always rises and only stops rising after running out of request. Then it doesn't automatically decrease Here my gradle compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '1.3.5.RELEASE' Here config in my spring-config.xml file

<mongo:mongo host="127.0.0.1" port="27017">
        <mongo:options connect-timeout="1000" max-wait-time="1500"
            auto-connect-retry="true" socket-keep-alive="true" socket-timeout="1500"
            slave-ok="true" write-number="1" write-timeout="0" write-fsync="true" />
    </mongo:mongo>

    <mongo:db-factory dbname="TabnGo" />


    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg ref="mongo" />
        <constructor-arg name="databaseName" value="TabnGo" />


In call mongoTemplate in code:

protected MongoOperations getMongoOperation() {
        @SuppressWarnings("resource")
        ApplicationContext mongoApp = new GenericXmlApplicationContext(
                "spring-config.xml");
        return (MongoOperations) mongoApp.getBean("mongoTemplate");
    }

Please Help Me......

hoanghunguet avatar Jun 28 '16 09:06 hoanghunguet

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Having said that, your getMongOperation() creates a new ApplicationContext every time it is invoked and you never close it either. First of all, you shouldn't do that at all and use proper injection instead. Then, it's obvious you'll have a memory leak if you create a context that you don't close.

snicoll avatar Jun 28 '16 09:06 snicoll