Parameters Testoncreate,testwhileidle,testonborrow and Testonreturn for REDIS (Jedispool)

Source: Internet
Author: User
Tags redis throwable

Process

"Testonreturn parameter" Jedispool.returnresource (Jedis)->pool.returnobject (Jedis)->pool.gettestonreturn ()
                                                             |          
                                                           |                
                                                                     |  
 |   
                                                      "Testonborrow parameter" Jedispool.getresource ()->pool.borrowobject () |              |
                                                         |
                                                           \           |
                                                             \         |
                                                              \       |   _\| \|/Pooledobjectfactory.validateobject (pooledobject<t>
                                                                  )|
                                                                  |--->jedisfactory.validateobject (pooledobject<jedis>)-->ping-pass, not through destruction
                                                                  |
 |-->shardedjedisfactory.validateobject (ooledobject<jedis>)-Cluster all nodes ping pass, not through destroy

Org.apache.commons.pool2.impl.GenericObjectPool.borrowObject (Long Borrowmaxwaitmillis) throws Exception

Public T Borrowobject (long Borrowmaxwaitmillis) throws Exception {Assertopen ();
        Abandonedconfig ac = this.abandonedconfig;
                if (AC! = null && ac.getremoveabandonedonborrow () && (Getnumidle () < 2) && (Getnumactive () > Getmaxtotal ()-3))
        {removeabandoned (AC);

        } pooledobject<t> p = null; Get local copy of current Config so it's consistent for entire//method execution Boolean Blockwhenex

        hausted = getblockwhenexhausted ();
        Boolean create;

        Long waitTime = System.currenttimemillis ();
            while (p = = null) {create = false;
                if (blockwhenexhausted) {p = Idleobjects.pollfirst ();
                    if (p = = null) {p = create ();
                    if (P! = null) {create = true; }} if (P == null) {if (Borrowmaxwaitmillis < 0) {p = Idleobjects.takefirst ();
                                } else {p = Idleobjects.pollfirst (Borrowmaxwaitmillis,
                    Timeunit.milliseconds);
                            }} if (p = = null) {throw new Nosuchelementexception (
                "Timeout Waiting for Idle object");
                } if (!p.allocate ()) {p = null;
                }} else {p = Idleobjects.pollfirst ();
                    if (p = = null) {p = create ();
                    if (P! = null) {create = true; }} if (p = = null) {throw new Nosuchelementexception ("Pool exhausted"
                ); } if (!p.allocate ()) {p =Null
                }} if (P! = null) {try {factory.activateobject (P);
                    } catch (Exception e) {try {destroy (P);
                    } catch (Exception E1) {//Ignore-activation failure is more important}
                    p = null;
                                if (create) {nosuchelementexception Nsee = new Nosuchelementexception (
                        "Unable to activate object");
                        Nsee.initcause (e);
                    Throw Nsee; 
                    }} if (P! = null && (Gettestonborrow () | | | Create && gettestoncreate ())) {
                    Boolean validate = false;
                    Throwable validationthrowable = null; try {validate = Factory.validateobject (p);
                    } catch (Throwable t) {Poolutils.checkrethrow (t);
                    validationthrowable = t;
                            } if (!validate) {try {destroy (P);
                        Destroyedbyborrowvalidationcount.incrementandget ();
                        } catch (Exception e) {//Ignore-validation failure is more important
                        } p = null;
                                    if (create) {nosuchelementexception Nsee = new Nosuchelementexception (
                            "Unable to validate object");
                            Nsee.initcause (validationthrowable);
                        Throw Nsee;  }}}}} Updatestatsborrow (P, System.currenttimemillis ()

     -WaitTime);   return P.getobject (); }

• • •

Related Article

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.