> Hi Gurus,
>
> I have a problem developing my application. The main
> requirement is that I MUST use just 1 connnection for
> all users. So, my question is, what kind of patten
> should I use so as to control this issue.
>
> Thanks in advance
I assume you mean 1 DB connection.
A 3-tier (not necessarily EJB) architecture will make this possible. If you expect to have a lot of users, you might want to implement asychronous transactions where possible and use JMS.
> Hi Gurus,
>
> I have a problem developing my application. The main
> requirement is that I MUST use just 1 connnection for
> all users. So, my question is, what kind of patten
> should I use so as to control this issue.
>
> Thanks in advance
... and instead of a singleton, use a framework ensuring your connection object gets created but once and made available to other objects that need it
> > You could also consider using a connection pool
> that
> > only has a size of 1.
> >
> > - Saish
>
> Isn't the that the only obvious solution? The OP
> still needs to have only one instance of this pool,
> if I understand correctly.
The pool itself is usually a Singleton, isn't it? So, that should be okay. Maybe I am not getting something.
- Saish
Hi,
Connection is not thread safe.
If you want to use only a connection you could use a monothread servlet or a pool on 1 connection.
I recommend that you use a pool of 1 connection in order to add more connection to the pool if you have problem.
I think that if you system need you could pay for more connection.
This solution make simple the addtion of connection
> You can use Singleton pattern but iam still wondering
> why do u need only one Connection? Definitly some
> problem is there with your design.
It not the design, it's a requirement. And again a singleton doesn't necessarily solve this. Singletons are only unique per classloader in Java. If this is a client server app, every use instance has a Singleton instance. That means if there is more than one user using the system, there is more than one connection in use.
You cannot assume this is a web app running in a single VM with a single classloader.
> You cannot assume this is a web app running in a
> single VM with a single classloader.
i think you worry too much. a client invokes a web function via a servlet. usually if the client sticks to one servlet, there wont be multiple instances of the connection; unless of course you do unusual things such as multiple instances of a servlet...
> > You cannot assume this is a web app running in a
> > single VM with a single classloader.
>
> i think you worry too much. a client invokes a web
> function via a servlet. usually if the client sticks
> to one servlet, there wont be multiple instances of
> the connection; unless of course you do unusual
> things such as multiple instances of a servlet...
Show me where the OP says this is a servlet. And no, it's not unusual to run multple VMs. That's what real enterprises architectures do. That you think this is unusual just reaffirms that you don't really know what you are writing about. Have you ever heard of clustering? You think that large websites with 100,000s of thousands of users have a single VM on a single server?
> > Show me where the OP says this is a servlet.
>
> as long as you are talking about a web application,
> servlets are there, and all client invocations are
> done via servlets.
I can't recall ever using a servlet in the perl or C web servers that I have worked on.
> I can't recall ever using a servlet in the
> perl or C web servers that I have worked on.
i trust that you are telling the truth, and i also trust that you hopefully correctly used whats called cgi scripts for those things at that time. you may argue they are not exactly the same thing, yet from the functional perspective, they served the same purpose, and that is: all client invocations have to go through them.
> > I can't recall ever using a servlet in the
> > perl or C web servers that I have worked on.
>
> i trust that you are telling the truth, and i also
> trust that you hopefully correctly used whats called
> cgi scripts for those things at that time. you may
> argue they are not exactly the same thing, yet from
> the functional perspective, they served the same
> purpose, and that is: all client invocations have to
> go through them.
Truth about what?
Are you trying to claim that you have used a servlet in C and/or perl? Or that they exist?
And no cgi is not the same as a servlet.
Hi,
I think that you must could one connection.
I think that you must use a Synchonized form. SingleThread Model is very hard, you could make some thing until use the connection.
Synchonized the get of the connection and the use of connection only.
Synchonized()
{
getConnection()
use connection();
}
You must try to Synchonized the minimal of code.