I\'m writing code for spark in java. When I use foreachAsync spark fails and gives me java.lang.IllegalStateException: Cannot call methods on a stopped Sp
foreachAsync
java.lang.IllegalStateException: Cannot call methods on a stopped Sp
It's because foreachAsync returns a Future object and when you leave a function, the spark context is closed (because it's created locally).
If you call get() on foreachAsync() then main thread will wait for the Future to complete.
get()
foreachAsync()