Shared connection or individual connection?
Dear All
I would like to ask your opinion on this. We have a java socket application which will keep receiving data from devices then each data will go through numerous different sql query selects, inserts and updates. The problem now we are looking into two solution
Send
1.Solution 1
For the socket connection build one thread and read the data and enqueue. Thenan other thread called is the dbprocessor to dequeue the data and do the processing of the different sql queries. The dbprocessor thread will just share on db connection for all messages being processed.
2. Solution 2.
The socket connection and both db processor are all in one single thread. For each socket connection open one db connection and keep processing the sql queries for each input data and finally close the db connection.
So which one is advice the share connection or each single d/b connection. We are using the share connection but at times the queue size becomes big and that worries us.
Re: Shared connection or individual connection?
Well, why don't you implement both? As soon as queue size gets big, switch to the second solution and keep altering the solutions within your application according to data processing needs.
Re: Shared connection or individual connection?
Dear 777,
How to implement both that will be very complex right?Thank you.
Re: Shared connection or individual connection?
How you define complexity?
Implement both solutions, and switch to either one according to your defined criteria of switching.
Re: Shared connection or individual connection?
Dear 777,
What I mean by complexity is due to first solution is that it will have 2 different thread for processing? Then the solution 2 will be just one single thread? So I will be making socket connection so how to move to different method just by doing a simple if and else? Do you think is possible? Thank you.
Re: Shared connection or individual connection?
Quote:
so how to move to different method just by doing a simple if and else?
In your solution as soon as queue gets big, switch to the second one. I am sure this can be done easily.
And switch to the one again, as soon as you find that queue gets empty or small.
Re: Shared connection or individual connection?
Dear 777,
I have implemented connection pooling for sometimes and is working well. Hope that is ok.