Statics and threading

G

Guest

Hi

I am writing a fairly simple desktop app which will not be subject to great loads. Therefore this question is more for academic purposes

I have implemented a class that declares only static members and functions. I use this class to control my connections. There are just 2 methods; Open and Close. The connection object within the class is static and has public scope. It is created when the app is started. (This obviously enables connection pooling

This makes the code very simple. When I want to use a connection I just call myConnectionClass.Conn. No need to dimension anythinig, dispose etc. I just make sure I close it when the routine has finished

Is this OK? I am worried that by declaring just 1 connection as a static there will be threading issues. i.e. There may be a que of users waiting to use the single, shared connection object

What do you experts think

Andy Newland (MCAD
 
S

Steve McLellan

Hi,
I am writing a fairly simple desktop app which will not be subject to
great loads. Therefore this question is more for academic purposes!
I have implemented a class that declares only static members and
functions. I use this class to control my connections. There are just 2
methods; Open and Close. The connection object within the class is static
and has public scope. It is created when the app is started. (This obviously
enables connection pooling)
This makes the code very simple. When I want to use a connection I just
call myConnectionClass.Conn. No need to dimension anythinig, dispose etc. I
just make sure I close it when the routine has finished.
Is this OK? I am worried that by declaring just 1 connection as a static
there will be threading issues. i.e. There may be a que of users waiting to
use the single, shared connection object.
What do you experts think?

What are you connecting to? How many people are doing it? Is there a good
reason to limit things to one connection? If you're designing an FTP server,
then things need to be more complex. If you're designing a simple point to
point application between 2 processes or machines it might work. Make sure
you understand the consequences of any design decisions you make, and
providing more detail would help people give you better advice.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top