aspose file tools*
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads in Database connectivity !" Watch "Threads in Database connectivity !" New topic
Author

Threads in Database connectivity !

Mayank C
Greenhorn

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
Hi,
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.
Thanks,
Steve
Mayank C
Greenhorn

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 ?
Thanks.
Mayank
Ajith Kallambella
Sheriff

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
Wanderer
Sheriff

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
Greenhorn

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 .
Thanks,
Mayank
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads in Database connectivity !