Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection pooling? #31

Open
funkysandman opened this issue Jul 19, 2023 · 1 comment
Open

connection pooling? #31

funkysandman opened this issue Jul 19, 2023 · 1 comment

Comments

@funkysandman
Copy link

Any advice on how to achieve connection pooling with a jdbc.net connection? I'm using this for a web api and looking to reduce overhead of opening connections

@tcables
Copy link
Contributor

tcables commented Jul 19, 2023

Use the Factory Pattern to provide connections that you pool. Wrap the JdbcConnections in a class that can hold a reference to the pool, that which the pool will recycle it when you finish using it in a using statement (disposable).

In the factory keep a list of wrapped-connections private JdbcConnectionWrapper[] Connections = new JdbcConnectionWrapper[POOL_SIZE];. and a list of locks private int[] Locks = new int[POOL_SIZE];.
locks[i] is 0 for free or 1 for in use. when requesting a connection loop over connections pool and check for unused connections. Interlocked.CompareExchange(ref Locks[i], 1, 0) == 0 is your friend (atomic / locking). I'd post all of my code, but I'd need approval from my boss.

also, take a moment to see my pull request for making JDBC.NET web api compatible:
#29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants