This is certainly the advice given if you're ruthlessly careerist, and it can be a good strategy if you're still looking for that dream role, but it can also backfire on you.
As someone who often needs to recruit I pay fairly close attention to the stability of an applicant's career. In general I don't like to see a lot of job-hopping unless it's in the early years of someone's career, because it can be hard to find a role you really like. Periods of contracting are another exception, although some evidence of stable employment for some period is also beneficial.
Recruiting is hugely important, but sucks a lot of time and effort from a team, and incurs significant costs, both direct and indirect. If you've been working for a decade and have never been in a job for more than 2 years that can be a pretty big turn-off.
You could of course argue that because I'd prefer to recruit people who will stay for more than 2 years, the roles I have available may not suit you.
Bottom line: there's a trade-off you're potentially making by behaving this way, which is fine, but it's important you understand that fact. Still, it's a good idea to start looking for a new job before you've started to hate the old one (bitter experience speaking right here): leave on a high because it'll probably set you up much better for the future.