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 8741937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:24:30+00:00 2026-06-13T11:24:30+00:00

I am developing an WebApp and would like to know if there is any

  • 0

I am developing an WebApp and would like to know if there is any pros/cons of sharing JDBC connection object between methods

So the situation is

  • It is a WebApp and multiuser environment (aprox 1000 user using at a same time)
  • I am using a container that supports connection pooling (Weblogic Server)
  • I use Transactions in my JDBC calls
  • Most of my JDBC calls are single record insert/Update but select/delete can happen in bulk

Now i have two approach

Approach 1
Open the connection object once and relay it across the methods

// Just a Pseudo Code

Cn = OpenJDBConnection() // This will open up the  connection 
obj.Task1(Cn, Param1, Param2);
obj.Task2(Cn, Param1, Param2);
obj.Task3(Cn, Param1, Param2);
Cn.close();

Approach 2
Open and close the connection in each method

I am leaning on Approach 1 as that way i will be able to avoid some boilerplate code. but i am unsure will it be threadsafe ? i have a poolsize of 100 connection which i think is okay for 1000 users active at a given time

is there anything else too that i should be considering before adopting one of the approach

  • 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-13T11:24:31+00:00Added an answer on June 13, 2026 at 11:24 am

    Consider that transactions are managed at the connection level.

    For your simple use-case, approach #1 may work, but it’s easy to get into a situation where, for example, you have transaction pending on the connection, and call another method which does a select on the same connection, which will cause your transaction to commit (earlier than you expected).

    With properly-configured connection pooling, the overhead of releasing and re-obtaining a connection should be minmal, so I’d suggest approach #2. When pooled, closing the connection doesn’ really close it, it leaves it open and returns it to the pool.

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

Sidebar

Related Questions

While Developing a Java EE Web app, I would like to know simple ways
We are developing Web-App for Mobile browsers, we would like text of any input
I'm developing an ASP.NET Web app and would like the user to be able
I'm developing software on google app engine. I'm using the webapp framework. is there
I'm developing an ajax heavy web app, and would like to have textarea 's
I'm developing on the Google App Engine and I would like to integrate Facebook
I'm developing a web app based on videos that my client would like to
I know this question might be repeated many times but would really appreciate any
I would like to get some advice. I am developing a system that will
I'm developing a webapp that allows the editing of records. There is a possibility

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.