📄 fairgenericobjectpool.html
字号:
<a name="100" href="#100">100</a> <em> */</em><a name="101" href="#101">101</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/FairGenericObjectPool.html">FairGenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle) {<a name="102" href="#102">102</a> <strong>this</strong>(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);<a name="103" href="#103">103</a> }<a name="104" href="#104">104</a> <a name="105" href="#105">105</a> <em>/**<em>*</em></em><a name="106" href="#106">106</a> <em> * Create a new <tt>FairGenericObjectPool</tt> using the specified values.</em><a name="107" href="#107">107</a> <em> * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects</em><a name="108" href="#108">108</a> <em> * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})</em><a name="109" href="#109">109</a> <em> * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #getWhenExhaustedAction})</em><a name="110" href="#110">110</a> <em> * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #getMaxWait})</em><a name="111" href="#111">111</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #getMaxIdle})</em><a name="112" href="#112">112</a> <em> * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method (see {@link #getTestOnBorrow})</em><a name="113" href="#113">113</a> <em> * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method (see {@link #getTestOnReturn})</em><a name="114" href="#114">114</a> <em> */</em><a name="115" href="#115">115</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/FairGenericObjectPool.html">FairGenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <strong>boolean</strong> testOnBorrow, <strong>boolean</strong> testOnReturn) {<a name="116" href="#116">116</a> <strong>this</strong>(factory,maxActive,whenExhaustedAction,maxWait,maxIdle,DEFAULT_MIN_IDLE,testOnBorrow,testOnReturn,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE);<a name="117" href="#117">117</a> }<a name="118" href="#118">118</a> <a name="119" href="#119">119</a> <em>/**<em>*</em></em><a name="120" href="#120">120</a> <em> * Create a new <tt>FairGenericObjectPool</tt> using the specified values.</em><a name="121" href="#121">121</a> <em> * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects</em><a name="122" href="#122">122</a> <em> * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})</em><a name="123" href="#123">123</a> <em> * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})</em><a name="124" href="#124">124</a> <em> * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})</em><a name="125" href="#125">125</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})</em><a name="126" href="#126">126</a> <em> * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method (see {@link #setTestOnBorrow})</em><a name="127" href="#127">127</a> <em> * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method (see {@link #setTestOnReturn})</em><a name="128" href="#128">128</a> <em> * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})</em><a name="129" href="#129">129</a> <em> * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread (if any) (see {@link #setNumTestsPerEvictionRun})</em><a name="130" href="#130">130</a> <em> * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see {@link #setMinEvictableIdleTimeMillis})</em><a name="131" href="#131">131</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="132" href="#132">132</a> <em> */</em><a name="133" href="#133">133</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/FairGenericObjectPool.html">FairGenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <strong>boolean</strong> testOnBorrow, <strong>boolean</strong> testOnReturn, <strong>long</strong> timeBetweenEvictionRunsMillis, <strong>int</strong> numTestsPerEvictionRun, <strong>long</strong> minEvictableIdleTimeMillis, <strong>boolean</strong> testWhileIdle) {<a name="134" href="#134">134</a> <strong>this</strong>(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, DEFAULT_MIN_IDLE, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle);<a name="135" href="#135">135</a> }<a name="136" href="#136">136</a> <a name="137" href="#137">137</a> <em>/**<em>*</em></em><a name="138" href="#138">138</a> <em> * Create a new <tt>FairGenericObjectPool</tt> using the specified values.</em><a name="139" href="#139">139</a> <em> * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects</em><a name="140" href="#140">140</a> <em> * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})</em><a name="141" href="#141">141</a> <em> * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})</em><a name="142" href="#142">142</a> <em> * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})</em><a name="143" href="#143">143</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})</em><a name="144" href="#144">144</a> <em> * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})</em><a name="145" href="#145">145</a> <em> * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method (see {@link #setTestOnBorrow})</em><a name="146" href="#146">146</a> <em> * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method (see {@link #setTestOnReturn})</em><a name="147" href="#147">147</a> <em> * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})</em><a name="148" href="#148">148</a> <em> * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread (if any) (see {@link #setNumTestsPerEvictionRun})</em><a name="149" href="#149">149</a> <em> * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see {@link #setMinEvictableIdleTimeMillis})</em><a name="150" href="#150">150</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="151" href="#151">151</a> <em> */</em><a name="152" href="#152">152</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/FairGenericObjectPool.html">FairGenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <strong>int</strong> minIdle, <strong>boolean</strong> testOnBorrow, <strong>boolean</strong> testOnReturn, <strong>long</strong> timeBetweenEvictionRunsMillis, <strong>int</strong> numTestsPerEvictionRun, <strong>long</strong> minEvictableIdleTimeMillis, <strong>boolean</strong> testWhileIdle) {<a name="153" href="#153">153</a> <strong>this</strong>(factory, maxActive, whenExhaustedAction, maxWait, maxIdle, minIdle, testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis, testWhileIdle, DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);<a name="154" href="#154">154</a> }<a name="155" href="#155">155</a> <a name="156" href="#156">156</a> <em>/**<em>*</em></em><a name="157" href="#157">157</a> <em> * Create a new <tt>FairGenericObjectPool</tt> using the specified values.</em><a name="158" href="#158">158</a> <em> * @param factory the (possibly <tt>null</tt>)PoolableObjectFactory to use to create, validate and destroy objects</em><a name="159" href="#159">159</a> <em> * @param maxActive the maximum number of objects that can be borrowed from me at one time (see {@link #setMaxActive})</em><a name="160" href="#160">160</a> <em> * @param whenExhaustedAction the action to take when the pool is exhausted (see {@link #setWhenExhaustedAction})</em><a name="161" href="#161">161</a> <em> * @param maxWait the maximum amount of time to wait for an idle object when the pool is exhausted an and <i>whenExhaustedAction</i> is {@link #WHEN_EXHAUSTED_BLOCK} (otherwise ignored) (see {@link #setMaxWait})</em><a name="162" href="#162">162</a> <em> * @param maxIdle the maximum number of idle objects in my pool (see {@link #setMaxIdle})</em><a name="163" href="#163">163</a> <em> * @param minIdle the minimum number of idle objects in my pool (see {@link #setMinIdle})</em><a name="164" href="#164">164</a> <em> * @param testOnBorrow whether or not to validate objects before they are returned by the {@link #borrowObject} method (see {@link #setTestOnBorrow})</em><a name="165" href="#165">165</a> <em> * @param testOnReturn whether or not to validate objects after they are returned to the {@link #returnObject} method (see {@link #setTestOnReturn})</em><a name="166" href="#166">166</a> <em> * @param timeBetweenEvictionRunsMillis the amount of time (in milliseconds) to sleep between examining idle objects for eviction (see {@link #setTimeBetweenEvictionRunsMillis})</em><a name="167" href="#167">167</a> <em> * @param numTestsPerEvictionRun the number of idle objects to examine per run within the idle object eviction thread (if any) (see {@link #setNumTestsPerEvictionRun})</em><a name="168" href="#168">168</a> <em> * @param minEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition (see {@link #setMinEvictableIdleTimeMillis})</em><a name="169" href="#169">169</a> <em> * @param testWhileIdle whether or not to validate objects in the idle object eviction thread, if any (see {@link #setTestWhileIdle})</em><a name="170" href="#170">170</a> <em> * @param softMinEvictableIdleTimeMillis the minimum number of milliseconds an object can sit idle in the pool before it is eligable for evcition with the extra condition that at least "minIdle" amount of object remain in the pool. (see {@link #setSoftMinEvictableIdleTimeMillis})</em><a name="171" href="#171">171</a> <em> */</em><a name="172" href="#172">172</a> <strong>public</strong> <a href="../../../../../org/apache/commons/pool/impl/FairGenericObjectPool.html">FairGenericObjectPool</a>(PoolableObjectFactory factory, <strong>int</strong> maxActive, byte whenExhaustedAction, <strong>long</strong> maxWait, <strong>int</strong> maxIdle, <strong>int</strong> minIdle, <strong>boolean</strong> testOnBorrow, <strong>boolean</strong> testOnReturn, <strong>long</strong> timeBetweenEvictionRunsMillis, <strong>int</strong> numTestsPerEvictionRun, <strong>long</strong> minEvictableIdleTimeMillis, <strong>boolean</strong> testWhileIdle, <strong>long</strong> softMinEvictableIdleTimeMillis) {<a name="173" href="#173">173</a> <strong>super</strong>(factory, maxActive, whenExhaustedAction, maxWait, maxIdle,<a name="174" href="#174">174</a> minIdle, testOnBorrow, testOnReturn,<a name="175" href="#175">175</a> timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,<a name="176" href="#176">176</a> minEvictableIdleTimeMillis, testWhileIdle,<a name="177" href="#177">177</a> softMinEvictableIdleTimeMillis);<a name="178" href="#178">178</a> _borrowerQueue = Collections.synchronizedList(<strong>new</strong> LinkedList());<a name="179" href="#179">179</a> }<a name="180" href="#180">180</a> <a name="181" href="#181">181</a> <em class="comment">//-- ObjectPool methods ------------------------------------------</em><a name="182" href="#182">182</a> <a name="183" href="#183">183</a> <em>/**<em>* </em></em><a name="184" href="#184">184</a> <em> * </em><a name="185" href="#185">185</a> <em> * @see org.apache.commons.pool.ObjectPool#borrowObject()</em><a name="186" href="#186">186</a> <em> */</em><a name="187" href="#187">187</a> <strong>public</strong> Object borrowObject() throws Exception {<a name="188" href="#188">188</a> assertOpen();<a name="189" href="#189">189</a> <strong>long</strong> starttime = System.currentTimeMillis();<a name="190" href="#190">190</a> <a name="191" href="#191">191</a> <a name="192" href="#192">192</a> <a name="193" href="#193">193</a> <strong>try</strong> {<a name="194" href="#194">194</a> <strong>synchronized</strong>(<strong>this</strong>) {<a name="195" href="#195">195</a> <em class="comment">// use borrowerQueue</em><a name="196" href="#196">196</a> _borrowerQueue.add(Thread.currentThread());<a name="197" href="#197">197</a> <a name="198" href="#198">198</a> <strong>for</strong>(;;) {<a name="199" href="#199">199</a> ObjectTimestampPair pair = <strong>null</strong>;<a name="200" href="#200">200</a> <a name="201" href="#201">201</a> <em class="comment">// Only allow current thread to receive pool object if</em><a name="202" href="#202">202</a> <em class="comment">// thread is top of queue </em><a name="203" href="#203">203</a> <strong>boolean</strong> eligible = _borrowerQueue.get(0)==Thread.currentThread();<a name="204" href="#204">204</a> <strong>if</strong>(eligible) {<a name="205" href="#205">205</a> <em class="comment">// if there are any sleeping, just grab one of those</em><a name="206" href="#206">206</a> <strong>try</strong> {<a name="207" href="#207">207</a> pair = (ObjectTimestampPair)(_pool.removeFirst());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -