I think it started as a measure of self protection after a long string of broken promises when I was a kid, but it's a shitty way to live. My biggest realization was just that pessimism is no more logical than optimism.
My solution has been to give equal time to positive thoughts. So, if I find myself thinking for a couple minutes about how something might go horribly wrong, I spend the next couple minutes imagining what the best case scenario would be like.
I'm basically forcing hope back into my life.