This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Threads in Database connectivity ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads in Database connectivity !" Watch "Threads in Database connectivity !" New topic

Threads in Database connectivity !

Mayank C

Joined: Jul 18, 2002
Posts: 7
I want to use Threading concept while i am connecting to any database . As we create child threads , can I create a similar child connections from the main connection(connected to database). The main connection's job is to monitor whether any child connections are open . If no connections are open , it should close itself . All the database transactions will be carried out only by the child connections .
Can i use threads for this ? How ?
Your help will be highly appreciated.
Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
Are you supposing that each child connection is a separate physical connection to the database or are you wanting to send multiple requests from multiple clients down a single physical connection?
I think what you need is a connection pool, which allows efficient use of connection resources.
Mayank C

Joined: Jul 18, 2002
Posts: 7
Hi,Thanks for replying.
Actually,it should be only one physical connection from which we can send many Database requests . The connection should remain all the time . Is it possible ?
And how ?
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
Store the connection handle as a static variable in the parent class :roll: ?

Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
And don't forget to synchronize all access to the Connection object using static synchronized methods. Which may limit the efficiency of your threads a bit, but if you're determined to make them share a connection, they've got to play nice after all...

"I'm not back." - Bill Harding, Twister
Mayank C

Joined: Jul 18, 2002
Posts: 7
Thanks for the suggestion .
Can you post a sample code telling how to make the connection thread into N child threads.
I am not able to find out from where to start the code .
I agree. Here's the link:
subject: Threads in Database connectivity !
It's not a secret anymore!