How to use sleep mode sessions?

The structure of my program is as follows:

Inside my main java class:

for () // this will execute for say 5000 times ---- LINE 1
{
    // do select on Database1 (this will select say 10000 rows) ---- LINE 2

    // do some computations (mainly string operations) ---- LINE 3

    call function1() // this will do some update on Database1 ---- LINE 4
}

Now I am trying to access Database1 using Hibernate. My question is how to use a sleep session to access it. When should I start a session, and when should I end it?

If I run it before the for () loop, can I pass the same session to function1 () because it is accessing the same database? Or as soon as I make a choice (LINE 1), do I need to close it and open a new session in function1 ()? Optimizing overall performance and minimizing overall execution time is my main concern.

I am new to Hibernate. So please forgive me if I ask very stupid doubts.

+3
3

, , . , , .

, , .

+4

db, , . getCurrentSession(). , - , C3P0, . .

+1

10K, , Hibernate 50M-, .

.

+1

All Articles