According to the narrations, masturbation is a sin and is compared to doing zina with oneself.
We have an example of when Imam Ali (as) had to discipline someone for doing so:
“Once a person was caught masturbating and was brought to Imam 'Ali. The Imam punished him by beating his hands until they turned red; then he made an arrangement for his marriage on government's expenses.
(Wasa'il, vol. 14, p. 267; vol. 18, pp. 574-5)”
Some non Muslim doctors and teachers may try to encourage such acts and say they are ‘healthy’ but such advice which contradicts the divine teachings is worthless.
Masturbation is usually associated with haram acts such as pornography and can turn into an unhealthy addiction which affects one both physically and psychologically.
A Muslim should try their upmost to have self control and dignity. Therefore, seeking marriage whether permanent or temporary is necessary to protect one’s private parts.
A husband or wife may mutually stimulate each other’s private parts; for example, the wife masturbating the husband and vice-versa. If they are away from each other then they cannot use their own hands for such an action until being together.
May Allah swt grant you success