You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 use ZIO.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 calls ZIO.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 the OutputStream created by acquireOutputStream resides?
Thanks for help in advance!
Notice:
I have tried using ZIO NIO FileChannel with flatMapBlocking, but got the same results
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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