Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Does performance issue for each request getting the session and close the session?

  1. #1
    stsivaraj is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default Does performance issue for each request getting the session and close the session?

    Team,
    I need a clarification about session performance. I have created session pool(LocalSessionFactoryBean). I mean for each thread request I am getting a session(not created new one) from pool. For each request(from controller to serviceImpl), I am getting a session and once request is completed I just close the session. In this case, I feel session(currentSession and close session) is cause of performance issue for following ways. Please suggest me, which way is best in this situation.

    #WAY 1:
    =======
    TestController.java
    -------------------------
    for (String sdgCode : sdgCodes) {
    //For each sdgCode, I am calling serviceImpl
    // As per my knowledge, We are getting a session / close the session for each service request
    for (Feature sdgFeature : planService.getSharedDataGroupsFeature(sdgCode)) {

    }
    }

    #WAY 2:
    =======
    TestController.java
    ------------------------
    //One serviceImpl request and get the all feature objects
    //Only one session will play the role here. Only one time close the session.
    List<Feature> features = planService. getSharedDataGroupsFeatures(sdgCodes);
    for (Feature sdgFeature : features ){

    }

    Conclusion : Is it performance issue for each time getting the session from session pool and close the session for each request once request has been completed? Please suggest me…

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Does performance issue for each request getting the session and close the session

    Unless there is some logic that prevents you from using the second option then that would be the choice.
    However, it has nothing to do with sessions and everything to do with hitting the database the minimum number of times for the minimum needed information.
    For option 1 you would be making sdgCodes.length queries in order to get the information provided by the single query used int he second one (assuming the getSharedDataGroupsFeatures uses a sensible query).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Does performance issue for each request getting the session and close the session

    I wonder: why guess (you can't hide it with the word 'feeling') when you can do some time measurements in the code and have hard evidence if something is a performance hog or not? Using System.currentTimeMillis() can already take away most doubts without having to ever touch a profiler.
    Tolls likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    stsivaraj is offline Member
    Join Date
    Nov 2010
    Posts
    22
    Rep Power
    0

    Default Re: Does performance issue for each request getting the session and close the session

    Thanks for your reply. Sorry, I have some lack of knowledge to explain. My direct question is, each request I am getting the session from session pool and close it again. Instead I can use WAY#2 right? It will solve too many session close and session fetch from pool. Correct me If i wrong?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Does performance issue for each request getting the session and close the session

    It all depends how you want to manage your transaction.

    In other words, this is not a "this is the way to do it" question.

    If you have a transaction that logically requires you to interact with several tables, each represented by a different DAO, then you would have to pass around a single session.

    If this is a webapp (for example) then a transaction would usually cover a single request/response cycle...note the "usually" there.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. session.close() doesnt end database session.
    By ali_sakar in forum Hibernate
    Replies: 10
    Last Post: 12-12-2012, 10:53 AM
  2. listen session is close in spring mvc
    By javastuden in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2011, 12:04 PM
  3. Replies: 1
    Last Post: 04-21-2009, 11:20 PM
  4. Session and request in JSF
    By felixtfelix in forum Web Frameworks
    Replies: 0
    Last Post: 05-08-2008, 05:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •