The solution is to actually give a shit about the people around you. You don't have to be friends with everybody, but at least don't go out of your way to make someone else miserable.
Modern society has a bad case of 'Got mine' syndrome. As long as someone gets what they want they don't care who gets shafted in the process. Even if it's not specifically malicious, just small things like not holding the door for someone who is obviously right behind you, or not letting someone merge because you just have
to be 3 feet closer to your destination like it makes a difference, but that 3 feet is preventing someone from getting over, making them miss their exit.
Things like this build up over time. Most of the time these outbursts aren't due to one major event setting someone off. It's the culmination of constantly being slighted or ignored by the people around you just because helping you doesn't reap any kind of instant reward.
If the guy in front of you in line is a dollar short for lunch, offer to give him a buck. You never know if that guy had an assault rifle in the back of his car and after lunch planned to mow down his office. Your kindness may not stop him, but maybe it'll make him take a second look at the people around him.
All to often it's just 'inconvenient' to care about others. You don't have to donate to charity or go work for Green Peace to make a difference. All it takes is for you to look at the situations other people around you are in and maybe take that one extra step to try and make that situation better if you can.
Don't be the last straw. It's all you can really do.