Review thread local warnings (#196)

pull/197/head
Michael Barry 2022-04-27 07:24:14 -04:00 zatwierdzone przez GitHub
rodzic 2db49fc76f
commit b04f4cde0b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 13 dodań i 2 usunięć

Wyświetl plik

@ -123,9 +123,10 @@ public class MbtilesWriter {
WorkQueue<TileBatch> writerQueue = new WorkQueue<>("mbtiles_writer_queue", queueSize, 1, stats);
encodeBranch = pipeline
.<TileBatch>fromGenerator("read", next -> {
var writerEnqueuer = writerQueue.threadLocalWriter();
writer.readFeaturesAndBatch(batch -> {
next.accept(batch);
writerQueue.accept(batch); // also send immediately to writer
writerEnqueuer.accept(batch); // also send immediately to writer
});
writerQueue.close();
// use only 1 thread since readFeaturesAndBatch needs to be single-threaded

Wyświetl plik

@ -188,9 +188,10 @@ public class OsmReader implements Closeable, MemoryEstimator.HasEstimate {
var parsedBatches = new WorkQueue<WeightedHandoffQueue<OsmElement>>("elements", pendingBlocks, 1, stats);
var readBranch = pipeline
.<BlockWithResult>fromGenerator("read", next -> {
var parsedBatchEnqueuer = parsedBatches.threadLocalWriter();
osmBlockSource.forEachBlock((block) -> {
WeightedHandoffQueue<OsmElement> result = new WeightedHandoffQueue<>(handoffQueueBatches, 10_000);
parsedBatches.accept(result);
parsedBatchEnqueuer.accept(result);
next.accept(new BlockWithResult(block, result));
});
parsedBatches.close();

Wyświetl plik

@ -79,6 +79,9 @@ public interface Counter {
// keep track of all counters that have been handed out to threads so far
// and on read, add up the counts from each
private final List<SingleThreadCounter> all = new CopyOnWriteArrayList<>();
// Ignore warnings about not removing thread local values since planetiler uses dedicated worker threads that release
// values when a task is finished and are not re-used.
@SuppressWarnings("java:S5164")
private final ThreadLocal<SingleThreadCounter> thread = ThreadLocal.withInitial(() -> {
SingleThreadCounter counter = new SingleThreadCounter();
all.add(counter);

Wyświetl plik

@ -30,6 +30,9 @@ public class LayerStats implements Consumer<RenderedFeature> {
*/
private final List<ThreadLocalHandler> threadLocals = new CopyOnWriteArrayList<>();
// Ignore warnings about not removing thread local values since planetiler uses dedicated worker threads that release
// values when a task is finished and are not re-used.
@SuppressWarnings("java:S5164")
private final ThreadLocal<ThreadLocalHandler> layerStats = ThreadLocal
.withInitial(ThreadLocalHandler::new);

Wyświetl plik

@ -30,6 +30,9 @@ import java.util.function.Consumer;
*
* @param <T> the type of elements held in this queue
*/
// Ignore warnings about not removing thread local values since planetiler uses dedicated worker threads that release
// values when a task is finished and are not re-used.
@SuppressWarnings("java:S5164")
public class WorkQueue<T> implements AutoCloseable, IterableOnce<T>, Consumer<T> {
private final BlockingQueue<Queue<T>> itemQueue;