Atitit. Improved stability --- added the retry Mechanism in hibernate to solve database connection Shutdown

Source: Internet
Author: User

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;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.