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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:59:07+00:00 2026-05-15T16:59:07+00:00

I am using java to create an interface to connect to a database. Each

  • 0

I am using java to create an interface to connect to a database. Each time I want to make a call to the database I need to create new connections to the database, which would make calling the database say 10 times slow.

To avoid having to create new connections each time I want to call the database I have a java thread running that holds all of the connection information.

To write/read from the database I want to create a thread that uses the connection information stored in the thread that’s already running, use it to execute specified read/write functions, and then exit.

However I am having trouble accessing this information from the thread which is already running. What would be the best way to accomplish this?

  • 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-15T16:59:07+00:00Added an answer on May 15, 2026 at 4:59 pm

    Why do you need a thread running to keep your connection open, just store it somewhere and execute queries as soon as you need it.. should it work?

    In any case if you really want a thread you should care about having a synchronized collection (check Collections.asSynchronizedList) that can be accessed and managed from your thread and others too.

    To overcome visibility problems just declare it as a static final variable, so you won’t have any problems in accessing it from outside the thread you declared it into.

    Another easy solution (since connection seems to be not thread-safe) is not to use a thread but use just a monitor: you can easily manage a wait()/notify() mechanism for which a thread that wants to execute a query checks if connection is “free”. if it is occupies the monitor and do whatever it wants before notifying all waiting threads.

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

Sidebar

Related Questions

I want to create a custom annotation (using Java) which would accept other annotations
I am using Swig to create a Java interface. Basically, in C++ I have
I am using Java to create a graphical game and every time I wish
I need to create a prn file using java. Did a basic googling to
I need to create 1000 server sockets using Java. Somewhere between creating 600 and
i'm using sqlitejdbc libraries to create a db using java. Now i need to
I am working with a programmer who is using Java to create an interface
I am using java.sql.SQLData interface to map my java objects to Oracle database types.
I have a java project I want to create which will be built on
I want to create and publish simple WebService using Java. Everything compiles. When I

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.