Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Shared connection or individual connection?

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default 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.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Shared connection or individual connection?

    Dear 777,
    How to implement both that will be very complex right?Thank you.

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default 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.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Shared connection or individual connection?

    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.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  7. #7
    Junior Member
    Join Date
    Dec 2010
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Shared connection or individual connection?

    Dear 777,
    I have implemented connection pooling for sometimes and is working well. Hope that is ok.

Similar Threads

  1. Error in URL connection
    By HardikDobaria in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2012, 07:50 AM
  2. connection
    By sugukrish in forum JDBC & Databases
    Replies: 2
    Last Post: November 5th, 2011, 11:14 PM
  3. Replies: 0
    Last Post: March 26th, 2011, 11:07 AM
  4. Thread and connection
    By Param in forum Threads
    Replies: 0
    Last Post: April 26th, 2010, 03:43 AM
  5. cant get rid of http connection
    By kartik in forum Java Networking
    Replies: 1
    Last Post: July 21st, 2009, 03:09 AM