To get the identifier of a specific task, you can use TaskContext :
import org.apache.spark.TaskContext; textFile.map( x -> { TaskContext tc = TaskContext.get(); System.out.println(tc.taskAttemptId()); });
Keep in mind that a particular println will be printed on the node that is currently running, and not on the driver console.
source share