Reputation: 921
In my current project if something needs to be written in db asynchronously(to log some data) we are using thread pool executors. As It is just an IO operation instead of using thread for each write call can we have something similar to Event driven mechanism. Where a single thread will be running in while loop and will make async db call.similar to java NIO is done for network calls.
Upvotes: 0
Views: 303
Reputation: 73538
No, you're going to need at least one thread no matter what you do. If you did have a driver that uses NIO you would still have an extra thread that runs select()
.
I'm not sure how you've implemented it in your current project, but even when using executors (as was suggested, SingleThreadExecutor
is enough) it shouldn't be very complicated.
Upvotes: 1