How can I control my overthinking?

How can I control my overthinking? There are many thoughts that just run through my mind which makes me negative, I guess.

I broke up with my boyfriend but I think about him everytime. How can I stop thinking about it? It has affected my mental health a lot.