public interface BorrowedBuffer<T extends Buffer>
Modifier and Type | Method and Description |
---|---|
T |
lockAndGet()
Get the underlying buffer instance.
|
void |
release()
Release the underlying buffer.
|
void |
unlock()
Unlock the buffer, thus allowing to
release() it. |
T lockAndGet()
unlock()
.
Caller of this method SHOULD call unlock()
as soon as it's finished working with the buffer,
e.g. by using the same try-finally pattern as when working with locks:
This method will block the calling thread until the buffer is in UNLOCKED state.BorrowedBuffer<T> holder = ...; T buffer = holder.lockAndGet(); try { writeData(buffer); } finally { holder.unlock(); }
void unlock()
release()
it.IllegalMonitorStateException
- if the buffer is not locked or is locked by a different threadvoid release()
Copyright © 2016–2021. All rights reserved.