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

  • SEARCH
  • Home
  • 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 9262469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:21:25+00:00 2026-06-18T13:21:25+00:00

I have one basic question here – I am working with a new Database

  • 0

I have one basic question here – I am working with a new Database named XpressMP.

I wrote a multithreaded program to insert lots of records into the database. I noticed one most important thing while making a connection to database:

In my program, If I am using something like below-

class Task implements Runnable {

   private Connection dbConnection = null;
   private PreparedStatement preparedStatement = null;

   //other stuff

 @Override
  public void run() {

   try {

      dbConnection = getDBConnection();

   } finally {
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
                preparedStatement = null;
            } catch (SQLException e) {
            }
        }
        if (dbConnection != null) {
            try {
                dbConnection.close();
                dbConnection = null;
            } catch (SQLException e) {
            }
        }
    }
  }
}

it works fine and I am closing each and every connection in the final block. And I can insert a lot more rows to database.

But as soon as I start using static connection intentionally (which I shouldn’t be doing) with multiple threads-

class Task implements Runnable {

   private static Connection dbConnection = null;
   private static PreparedStatement preparedStatement = null;

   //other stuff

 @Override
  public void run() {

  try {

    dbConnection = getDBConnection();

   } finally {
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
                preparedStatement = null;
            } catch (SQLException e) {

            }
        }
        if (dbConnection != null) {
            try {
                dbConnection.close();
                dbConnection = null;
            } catch (SQLException e) {
            }
        }
    }
  }
}

The whole Database hangs. I cannot work with that database until I restart the db. So that means there is some problem with the JDBC driver that I have. I have told the DBA about this problem and they are talking with the folks who owned that Database.

But my question is why it hangs. For what reason?

  • 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-06-18T13:21:26+00:00Added an answer on June 18, 2026 at 1:21 pm

    You are sharing one object reference variable among various threads… Sometimes, one connection object is created and before it is closed (and its reference be set to null), another thread starts, creating another object and never closing the old one. So, that connection is still alive and in some point of the time, too much connections will be opened and your DBMS may crash, spiting some error like “too many connections”. The problem is not your drive, but your code. Note that some thread may close a connection that was created by another thread too!

    I think you are not seeing the exception that is being throw because you not have a catch in you outer try. The exception will be throw when ou try to create an connection. Try to put a catch there to show the stack trace. It will work (it might work) if your database is detecting this problem.

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

Sidebar

Related Questions

This is probably a basic html/css question... I have a simple one-button form that
i have a really basic java program just one .java/.class file (.java uncompiled .class
real basic question here: I'm new to Ocaml and I'm having issues trying to
Basic using threads question here. I'm modifying a program with 2 thread classes and
I have started learning HTTPUNIT and found one basic example. In this example it
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my
Sorry for the basic question. I have used unittest method to check my models
I have a rather basic C++ question: Consider a function that takes some input
I think this is very basic CSS question . But here is the fiddle
Background I have the most basic newbie AngularJS question, forgive my ignorance: how do

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.