Concurrent file write causes content overlap #8387
Unanswered
mykytamykhailenko
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have developed an app, which executes a few heavy queries, which yield a lot of data so I decided to write the query results to multiple files concurrently.
I create an
OutputStream
for each separate query and write the results concurrently.When I execute the code sequentially, everything works as expected (using
ZIO.collectAll
), but once I useZIO.collectAllPar
, content from one file can appear in the other.I think the issue described here: https://jenkov.com/tutorials/java-io/concurrent-io.html
I think the reason why this happens is because under the hood
writeStream
callsZIO.attemptBlockingIO(os.write(payload))
, and because of the ZIO's nature, it can be executed from different threads nondeterministically.So the question is: is there any way for ZIO to tell that
ZIO.attemptBlockingIO(os.write(payload))
should be executed on the same thread where theOutputStream
created byacquireOutputStream
resides?Thanks for help in advance!
Notice:
I have tried using ZIO NIO
FileChannel
withflatMapBlocking
, but got the same resultsBeta Was this translation helpful? Give feedback.
All reactions