People ask me: you've been commuting by bicycle for 25 years or more, and you're not dead: how do you do it? Well, it's simple. I have three rules that I apply.
1. Be critical of your route.
You go the same way every day. So you get used to it. It's a habit. But habits are not good if you want to be safe. My rule is simple. If I have an incident where I feel uncomfortable, or I think I'm going to not be safe then I change something. I might change the route. I might ride along the footpath (slowly, treating pedestrians with respect). If I feel unsafe then I do something about it.
2. Watch for the psychopath.
Roughly 1% of the population are psychopaths, it seems. Of that percentage, how many drive cars? Sometimes it seems like all of them. I once had a car drive across three lanes in order to try and hit me. Of course I could see them coming and had plenty of time to dodge. You might meet young bicycle riders who do things like riding three abreast in traffic, and ignoring the tooting that results. You don't meet old bicycle riders in this category. There is a reason for this. Sure, not every driver is a psychopath, but it only takes one.
3. Be very highly visible at all times.
If it's dark, you might think of wearing reflective clothing. Waste of time. Think of bright lights that are so bright that they might scar the retina of the driver. Just as they feel the pain of your lights, in their dim consciousness they will react and avoid you. You might be familiar with the saying "there is none so blind as they who will not see". In the dim recesses of the car driver's brain is "truck, watch out, car, watch out." Nothing about bicycles. So you need to substitute with the thought "man, that light is so bright, maybe it's an alien come to eat me."
A bleak view of humanity, you might think. But I'm still here, and still riding my bicycle around in traffic. Lots of my compatriots are not.