The solution is to notice what’s happening in your head before your thoughts have a chance to build any momentum. The sooner you catch yourself in the act of building your mental snowball, the easier it is to stop.
This is what "mindfulness" is. Being the observer of the thoughts. Noticing that your obessively thinking. This can happen during formal meditation practice or any time throughout the day. Thoughts think themselves; there is no need to identify with them.

