CompletableFuture and cloning results

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

CompletableFuture and cloning results

JSR166 Concurrency mailing list
Hello,

what is the best way to clone/deserialize a result set on a CompletableFuture?

So I want to be able to set a serialized value on a CompletableFuture, and each get/join etc needs to deserialize the value so that each call to get/join will lead to a new object.

We are currently using a custom Future implementation (Java 6 unfortunately) for remote invocations and I'm looking at how to switch to the CompletableFuture.

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: CompletableFuture and cloning results

JSR166 Concurrency mailing list
There's a strong expectation that future.get() == future.get() for any Future.

You probably want to build a new abstraction on top of an existing Future implementation, like CompletableFuture.

On Thu, Apr 26, 2018 at 9:43 PM, Peter Veentjer via Concurrency-interest <[hidden email]> wrote:
Hello,

what is the best way to clone/deserialize a result set on a CompletableFuture?

So I want to be able to set a serialized value on a CompletableFuture, and each get/join etc needs to deserialize the value so that each call to get/join will lead to a new object.

We are currently using a custom Future implementation (Java 6 unfortunately) for remote invocations and I'm looking at how to switch to the CompletableFuture.

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: CompletableFuture and cloning results

JSR166 Concurrency mailing list
In reply to this post by JSR166 Concurrency mailing list
You need not to deserialize your object each time - you can use
Object#clone() to get different instances.
That is, given you have
CompletableFuture myFuture = ...;
just call:
myInstance = myFuture.get().clone();

Or override the method get():

class CloningCompletableFuture<T> extends CompletableFuture<T> {
    T get() {
       return super.get().clone();
    }
}
   
CompletableFuture myFuture = new CloningCompletableFuture();
...
myInstance = myFuture.get();




--
Sent from: http://jsr166-concurrency.10961.n7.nabble.com/
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest