Use "on the thread" to mean that a thread (usually named) is going to carry out a task. For example, events can be dispatched "on the Event thread." One might also say that "graphics rendering occurs on the UI thread." You wouldn't ordinarily refer to code as running "on the thread," but instead used to describe what task runs in that context. This is roughly analogous to running something "on a server."
Use "in the thread" to mean that a thread (possibly unnamed) is running code. Threads are abstract concepts that operate like a box, and on all modern systems, code runs within that context, and are therefore "in the thread." It's usually described in a general way to conceptualize how threads work.
There is usually only one right way to refer to in/on the thread, and you'd have to use the correct context or it might sound odd to professional or experienced developers.