From 544b46ffe1a19bb263a8ff268b89518566bb5627 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 21 Apr 2022 17:04:01 +0200 Subject: [PATCH] Revert "flush stanzas in batches" This reverts commit 6bd552f6a32ca93826cb491f9b4bd757f9698227. fixes #4313 This turned out to be a rather unnecessary optimization that might cause problems with wake locks (the app is no longer awake after the 400ms timeout) --- .../eu/siacs/conversations/xml/TagWriter.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xml/TagWriter.java b/src/main/java/eu/siacs/conversations/xml/TagWriter.java index 2c2b8ac2c..4f429377a 100644 --- a/src/main/java/eu/siacs/conversations/xml/TagWriter.java +++ b/src/main/java/eu/siacs/conversations/xml/TagWriter.java @@ -8,15 +8,12 @@ import java.io.OutputStreamWriter; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; import eu.siacs.conversations.Config; import eu.siacs.conversations.xmpp.stanzas.AbstractStanza; public class TagWriter { - private static final int FLUSH_DELAY = 400; - private OutputStreamWriter outputStream; private boolean finished = false; private final LinkedBlockingQueue writeQueue = new LinkedBlockingQueue(); @@ -24,8 +21,6 @@ public class TagWriter { private final Thread asyncStanzaWriter = new Thread() { - private final AtomicInteger batchStanzaCount = new AtomicInteger(0); - @Override public void run() { stanzaWriterCountDownLatch = new CountDownLatch(1); @@ -34,21 +29,12 @@ public class TagWriter { break; } try { - final AbstractStanza stanza = writeQueue.poll(FLUSH_DELAY, TimeUnit.MILLISECONDS); - if (stanza != null) { - batchStanzaCount.incrementAndGet(); - outputStream.write(stanza.toString()); - } else { - final int batch = batchStanzaCount.getAndSet(0); - if (batch > 1) { - Log.d(Config.LOGTAG, "flushing " + batch + " stanzas"); - } + AbstractStanza output = writeQueue.take(); + outputStream.write(output.toString()); + if (writeQueue.size() == 0) { outputStream.flush(); - final AbstractStanza nextStanza = writeQueue.take(); - batchStanzaCount.incrementAndGet(); - outputStream.write(nextStanza.toString()); } - } catch (final Exception e) { + } catch (Exception e) { break; } }