• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is really a connection, statement? Can several sessions multiplex one connection

 
Allan Wang
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi java fans,
When we use connection, is it really like a socket? But what is the statement? If I use only one connection in my servlet, can these sessions share one connection and haven't collisions?
Any one can throw some light on it.
allan
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Connections aren't really like Sockets. They're well "connections" to the database. Think of them as being a part of the database moved over into your Java program.
The problem with sharing a single connection is that transactions in JDBC are done at the connection level. You most certainly do NOT want multiple servlet threads to participate in the same transaction. That's why the common solution is to pool them so that each thread gets one of N connections out of a pool and then releases it back to the pool when it's finished with its transaction.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Allan Wang
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kyle Brown, thanks very much.
You mean sharing a connection will affect the transactions result. I think what your mean is when I begin a transaction A and didn't commit, then I begin another transaction B in same connection and also didn't commit. Maybe for some reson, transaction A encounter some problem and rollbacked, so it will result in operations of transaction B will also be rollbacked. Is what I think right?
thanks,
allan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic