Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61548630
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
Tue, May 7, 09:10
Size
1 KB
Mime Type
text/x-java
Expires
Thu, May 9, 09:10 (2 d)
Engine
blob
Format
Raw Data
Handle
17526769
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