Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6059943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:46:08+00:00 2026-05-23T08:46:08+00:00

I am currently working with Java, MongoDB and several threads. For each threads, I

  • 0

I am currently working with Java, MongoDB and several threads.

For each threads, I run MongoDB connection.

private Mongo m;
m = new Mongo();

I had a look to the memory usage with TOP and I saw multiple instances of MongoDB Jar (call to library mongo-2.6.3.jar). I tried to destroy it after end of processing of each thread with :

m.close();
m = null;
System.gc();

But nothing instances are still in memory until my program is stopped.

Any ideas ? Thanks.


OK I have made some tests regarding the tutorial, but not very successful.
In fact, I have :

public class process {
    public static Mongo m;
    public static DB db;

    public process() {
        m = new Mongo();
        //for each database
        threadDatabase thread = new threadDatabase(database);
        thread.start();
    }
}

public class threadDatabase extends Thread {
    public threadDatabase (String database) {
        this.database = database;
    }

    public void run() {
        process.db.requestStart();
        processDatabase(this.database);    
        process.db.requestDone(); 
    }


private boolean processDatabase(String dbname) {
        process.db = process.m.getDB(dbname);
        //getting data on the dedicated database
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:46:09+00:00Added an answer on May 23, 2026 at 8:46 am

    From the Java Tutorial about MongoDB

    The Mongo object instance
    actually represents a pool of
    connections to the database; you will
    only need one object of class Mongo
    even with multiple threads. See the
    concurrency doc page for more
    information.

    Nulling references and calling System.gc does not guarantee to free up or garbage collect any resources at all. Fur further information see this question.

    My advice: Only use one instance of Mongo per VM, the rest will be handled automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a java me application and I have this code: svgForm.setSVGEventListener(new
I'm currently working on a Java project that is emitting the following warning when
I am coming from Java and am currently working on a C# project. What
I'm currently working on a WebSphere 6.1 Web Project. In my java code, how
I'm currently working on a hobby project, written in Java, containing about two different
I'm currently working with a specialized, interpreted, programming language implemented in Java. As a
I'm working on a cross platform application in Java which currently works nicely on
I'm currently working on creating a new C# project that needs to interact with
Currently working in Java, i'd like to be able to select part of an
I'm currently working on a Java project which uses Tibco rendezvous control. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.