scala - What is the right way to have a static object on all workers - Stack Overflow
Note there are no fields or anything. If you look at the disassembled bytecode, all it does is call the func()
method. When running in Spark, this is the instance that will get serialized; since it has no fields, there's not much to be serialized.
As for your question, how to initialize static objects, you can have an idempotent initialization function that you call at the start of your closures. The first one will trigger initialization, the subsequent calls will be no-ops. Cleanup, though, is a lot trickier, since I'm not familiar with an API that does something like "run this code on all executors".
Read full article from scala - What is the right way to have a static object on all workers - Stack Overflow
No comments:
Post a Comment