Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads in Database connectivity !

 
Mayank C
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store the connection handle as a static variable in the parent class :roll: ?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Mayank C
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic