[SPARK-3896] Pool#checkSpeculatableTasks fask quit loop

1. invoking checkSpeculatableTasks is expensive, once true then return true
2. import section formatting