The problem of Compulsive masturbation must me management like any other addiction problem. Not masturbating can trigger a set of specific withdrawal symptoms of anxiety, restlessness, weakness, irritability, poor concentration, etc. These problems must be individually managed. Also one must develop a healthy habit and routine to keep one busy and occupied. All this treatment is tailor made to individuals needs. It would require a detailed workup and assessment.
Next Steps
I would suggest you to consult with a sexologist for further management. For more information regarding this problem you can ask a detailed query here on practo.
Health Tips
Don't worry. It is treatable.