You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Ali Akhtar <al...@gmail.com> on 2016/11/12 12:41:49 UTC
Deadlock in callbacks to async operations (Java)
At https://datastax.github.io/java-driver/manual/async/ the docs say to not
do any blocking operations within the callback of an async operation. This
example is given as one that can cause a deadlock:
ListenableFuture<ResultSet> resultSet = Futures.transform(session,
new Function<Session, ResultSet>() {
public ResultSet apply(Session session) {
// Synchronous operation in a callback.
// DON'T DO THIS! It might deadlock.
return session.execute("select release_version from
system.local");
}
});
Will the above example work if instead of session.execute, it was doing
session.executeAsync()?
Re: Deadlock in callbacks to async operations (Java)
Posted by Andrew Tolbert <an...@datastax.com>.
>
> Will the above example work if instead of session.execute, it was doing
> session.executeAsync()?
>
It will work as executeAsync will not block waiting on behavior in a I/O
thread (that may also happen to be the calling thread), so it is not
susceptible to deadlock.
To be extra safe, you could provide a separate executor as a second
argument to transform, but it isn't necessary in this particular case.
On Sat, Nov 12, 2016 at 6:41 AM Ali Akhtar <al...@gmail.com> wrote:
> At https://datastax.github.io/java-driver/manual/async/ the docs say to
> not do any blocking operations within the callback of an async operation.
> This example is given as one that can cause a deadlock:
>
> ListenableFuture<ResultSet> resultSet = Futures.transform(session,
> new Function<Session, ResultSet>() {
> public ResultSet apply(Session session) {
> // Synchronous operation in a callback.
> // DON'T DO THIS! It might deadlock.
> return session.execute("select release_version from
> system.local");
> }
> });
>
> Will the above example work if instead of session.execute, it was doing
> session.executeAsync()?
>