Atitit. Improved stability --- added the retry Mechanism in hibernate to solve database connection Shutdown
Atitit. Improved stability --- added the retry Mechanism in hibernate to solve database connection Shutdown
1. Process summary
Retry (5 times). invoke (xxx). test (). rest (). $ () throw OvertimeEX
Retry (5 times): throw OvertimeEX
Caller () // call the original api
Tester (): // return T/f
Reset () /// Reset the device
End ::
Tester ()
Command Case1 OK, return T
Case2 fail, returns F,> retry
Case3 ex, return F >>> retry
Author: old wow's paw Attilax iron, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://blog.csdn.net/attilax
2. class
Deprecated
Public abstract class retry
This trojan reset method
3. retryO7 with reset Method
Public static Session getSession (){
// Attilax old wow's paw i4148 o78
// For log rzt detail msg... normal use not neccesry...
RetryRzt rzt = new retryRzt ();
Return new retryO7 (5, rzt ){
@ Override
Public Boolean item (Object t) throws Exception {
// Attilax old wow's paw 11:49:37 June 9, 2014
Final Session sess = getSessionOri ();
This. setResetObj (sess );
List li = sess. createQuery ("select 1"). list ();
// Core. ex4test ();
If (li. size ()> 0 ){
This. setResult (sess );
Return true;
}
Return false;
}
// Return null;
@ Override
Public void reset (final Object sessObj ){
Core. log ("--- o79: conn is close, now startclose session ..");
Session sess = (Session) sessObj;
Sess. close ();
}
}. $ O69 ();
}
4. getSessionOri
Public static Session getSessionOri () throws HibernateException {
Session session = (Session) threadLocal. get ();
If (session = null |! Session. isOpen ()){
If (sessionFactory = null ){
RebuildSessionFactory ();
}
Session = (sessionFactory! = Null )? SessionFactory. openSession ()
: Null;
ThreadLocal. set (session );
}
Return session;
}