Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/src/main/java/org/koppe/epub/client/EpubAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -51,6 +52,7 @@ class EpubAdapter {
* Object mapper for transforming objects to json strings
*/
private final ObjectMapper mapper = new ObjectMapper();
private final ExecutorService executor = Executors.newSingleThreadExecutor();

// #region add epub
/**
Expand Down Expand Up @@ -334,7 +336,7 @@ class EpubAdapter {
}

final PagedRequestDto<EpubDto> finalResult = result;
Executors.newFixedThreadPool(1).submit(() -> {
executor.submit(() -> {
logger.info("Caching results of paged request in different thread");
if (finalResult.getContent() != null) {
logger.info("Trying to cache result content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
Expand Down Expand Up @@ -47,6 +48,10 @@ public abstract class AbstractCache<K, V> implements Cache<K, V> {
* Maximum number of elements
*/
private int maxElements = -1;
/**
* Executor service for threaded execution
*/
private final ExecutorService executor = Executors.newSingleThreadExecutor();

/**
* Calls {@link RefreshFunction#run(Object)} of the instances refresh function
Expand Down Expand Up @@ -208,7 +213,7 @@ public void setValue(K key, V value) throws CachingException {
lock.unlock();

if (maxElements >= 0 && cache.size() > maxElements) {
Executors.newFixedThreadPool(1).submit(this::removeOldest);
executor.submit(this::removeOldest);
}
}

Expand Down
Loading