Just FYI, there is some question that it is actually a dominance behavior. The best explanation I've seen is that it's a nice stress reliever, which would explain why some dogs hump air.
This link has very practical advice on when to stop humping: stop the humper in action, and see if the humpee siezes the opportunity to flee.
The Down & Dirty on Humping: Sex, Status, and Beyond | Dog Star Daily