Design consideration for multithreaded jdbc application using connection pooling

Posted on 2004-11-19
Last Modified: 2011-04-14
my application involves connecting to Oracle using connection pooling (with tomcat).

How to make sure that the db connection is thread safe???

Specially on working with blobs???

Question by:aimueller
    LVL 8

    Expert Comment

    basically you need to have a synchronized method while getting the connection from the pool
    public Connection getConnection()
    return connection

    this way it will be thread safe and each of your threads will be getting individual connections.

    Author Comment

    How to make sure that the db connection (Oracle) while reading a blob is thread safe???
    LVL 35

    Expert Comment


    you don't share connections between threads...  That would be a very bad thing...

    So you will basiacally be relying on the skills of the people who write your connection pool, and the JDBC driver itself...
    LVL 8

    Accepted Solution

    as i said before when u get the connection from the datasource your threads should each have their own connections... so dont make the connection variable as a common  variable which can be accessible to all the threads..... meaning dont make it static/final etc ettc...

    whenever you create a thread of a particular thread it should get its own connection object...
    so declare a connection variable in your class making it extend the Thread/implement Runnable..... inside the run method call the get Connection method to retrieve the connection from the DataSource and assign it to the connection variable.....

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
    The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now