First, learn as much as you can before having surgery. Find out what happens during surgery, and what to expect from the procedure. Gather information about what you'll need to do after surgery to avoid a stiff knee.
Second, be sure to follow the advice of your doctor and physical therapist about exercises and therapy after surgery. Patients who are consistent with a comprehensive rehabilitation program tend to avoid the complications of a stiff new knee joint.