Somewhat related, if you were to switch to using Kotlin for Android development and then used the co-routines you may find it easier to do hand
thread related operations like the one you posted without the fear of memory leakage.
The Google keywords for this would be
kotlin android coroutines.
By the way, you can use Kotlin source files and
Java source files in the same Android project. This may help with your migration to Kotlin.