Replies: 2 comments
-
Currently, no. In theory, a reactive/async API would help here but that's a ways off. |
Beta Was this translation helpful? Give feedback.
-
This is something I'm interested in experimenting with, and helping implement/test/refine. But I've dug through the code a bit and see that it'd be pretty tricky, since morphia is using the The only way I see to do it would be to stop using the standard MongoDB driver and use the "MongoDB Async Driver" instead. (https://mongodb.github.io/mongo-java-driver/3.0/driver-async/) Is that the best approach you know about? Switching isn't an insurmountable task but... yeah, that's a lot of work. I'd assume that we could use the async driver in "faux synchronous mode", to replicate current behavior. But I'm not sure it could be done without breaking backwards compatibility. |
Beta Was this translation helpful? Give feedback.
-
I want to call save() with
WriteConcern.ACKNOWLEDGED
, but I don't want to block the thread that's calling save() while waiting on the server. I'd like the serialization into BSON to happen in the current thread, but then the actual "wait for the server to say okay" part to happen in another thread. Is there a way to do that?In this situation, I can't just call save() from a different thread, because the @PrePersist handlers aren't thread-safe (and can't be made thread-safe) -- they need to be called from the current thread. But I don't want to block this thread waiting on networking response.
Beta Was this translation helpful? Give feedback.
All reactions