A senior judge has decried "yet another instance" of someone carrying a knife as he locked up a man for more than 20 years for attempting to murder someone in a park.