• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic