Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-499

Add support for connection validation

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.5
    • Component/s: Connection Management
    • None

      The Java MongoDB driver has a built-in connection pool. One of the downsides of a connection pool is that pooled connections may become stale or broken over time (oftentimes due to timeouts, network issues, etc.). As a result, many connection pooling implementations offer a mechanism by which pooled connections can be automatically validated (usually before use, after use, or periodically). Some examples include DBCP's validationQuery and c3p0's connection testing. It would be great if the Java MongoDB driver could also support for some means of connection validation. Such a feature need not be as complex or general as in the above implementations. For example, while arbitrary validation queries might be desirable in some cases, something as simple as a ping command seems like it would be sufficient to validate a connection in many cases.

      Test case:
      I've attached a rather contrived example which illustrates a case in which connection validation might be useful. To simulate connection failure, the test involves restarting mongod during a brief waiting period between two successive calls to MongoDB. The connection pool size is set to 1 to ensure that the pooled connection is used for the second call.

        1. MongoPoolTest.java
          2 kB
          Bryon Ross

            Assignee:
            Unassigned Unassigned
            Reporter:
            bross@playdom.com Bryon Ross
            Votes:
            7 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: