[SPARK-3543] Write TaskContext in Java and expose it through a static accessor.

I would remove this and the below function. I think it's better it the `TaskContext` class is not itself aware of being stored as a thread local. We can keep all the logic related to thread locals in the static code.