Support different cleaner strategies #28
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor to support the direct closing of the MappedByteBuffers and to solve issue #27.
The closing/cleanup is moved out of the
ReadOnlyMemMap
into separate cleaner classes.The current behaviour with a single threaded executor, which is used to schedule the cleanup with a 1 second delay, is implemented in
SingleThreadedCleanerWithWait
and kept as the default.But this default can lead to a severe issue (#27), if we create many readers very fast.
Even if we close them directly after we created them, the memory will be freed only after 1 second at the earliest. Even worse is the fact that we can create readers much faster (with multiple threads) than the single threaded executor can do the cleanup. With high enough rates we can use up the virtual memory space, resulting in an
OutOfMemory
exception.As we do not share the (not thread safe) readers between threads, we want the cleanup to happen as soon as we close the reader. So the memory is freed as soon as possible (and the caller thread is blocked).
This is implemented with the
DirectCleaner
.To use the
DirectCleaner
instead of the default behaviour, you have to set aDirectCleaner
instance as the cleaner to be used byReadOnlyMemMap
.This can (currently) only be done globally and not per reader via the
setMappedByteBufferCleaner
method.