Allow me to preface this with: I acknowledged this post has the 'Android' tag, however, my search had nothing to do with 'Android' and this was my top result. To that end, for the non-Android SO Java users landing here, don't forget about:
public static void main(String[] args{
Thread.currentThread().setName("SomeNameIChoose");
/*...the rest of main...*/
}
After setting this, elsewhere in your code, you can easily check if you're about to execute on the main thread with:
if(Thread.currentThread().getName().equals("SomeNameIChoose"))
{
//do something on main thread
}
A bit embarrassed I had searched before remembering this, but hopefully it will help someone else!