Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F122254733
BlockingObjectPool.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 16, 22:27
Size
1 KB
Mime Type
text/x-java
Expires
Fri, Jul 18, 22:27 (2 d)
Engine
blob
Format
Raw Data
Handle
27457003
Attached To
R7507 YCSB
BlockingObjectPool.java
View Options
package
com.yahoo.ycsb
;
import
java.util.Objects
;
import
java.util.concurrent.LinkedBlockingQueue
;
/**
*
*/
public
class
BlockingObjectPool
<
T
>
extends
AbstractObjectPool
<
T
>
{
public
BlockingObjectPool
(
int
maxObjects
,
ObjectPoolItemHandler
<
T
>
itemHandler
)
{
super
(
maxObjects
,
itemHandler
);
this
.
available
=
new
LinkedBlockingQueue
<>(
maxObjects
);
}
@Override
public
T
take
()
{
if
(
closed
)
{
throw
new
PoolAlreadyClosedException
();
}
T
object
=
available
.
poll
();
if
(
object
==
null
)
{
int
currentCount
=
objectCount
.
getAndUpdate
(
count
->
count
==
maxObjects
?
count
:
count
+
1
);
if
(
currentCount
==
maxObjects
)
{
while
(
object
==
null
)
{
try
{
object
=
((
LinkedBlockingQueue
<
T
>)
available
).
take
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
}
else
{
object
=
itemHandler
.
create
();
}
}
checkedOut
.
put
(
object
,
Objects
.
requireNonNull
(
object
));
return
object
;
}
}
Event Timeline
Log In to Comment