Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Future vs c# async await

Im a c# developer and now started transitioning to Java...and started comparing the features

i came across this Future in Java concurrency https://docs.oracle.com/javaee/6/tutorial/doc/gkkqg.html As per the documentation example it says Even if the payment processor takes a long time, the client can continue working, and display the result when the processing finally completes.

So can we assume Future is same as c# async await..if not please lemme know the difference...

As per my knowledge sync ,await i have used in mobile operations where we didnt want the UI thread to be blocked while it interacts with apis or service.

like image 415
shiv455 Avatar asked Oct 18 '22 22:10

shiv455


1 Answers

Future is just an interface. It is not capable of handling anything asynchronously by itself. You receive a Future object when you submit some work to be executed asynchronously in an ExecutorService. Use Future.get() to block the current thread until the result is ready. Of course you should do something useful in the current thread between the time you submit the work and try to get the result.

like image 180
mvd Avatar answered Oct 21 '22 16:10

mvd