While exercise has long been a prescription for insomnia, new research suggests that exercise does not immediately translate into a better night's sleep — unless you stick with it for months.

A study published Thursday in the Journal of Clinical Sleep Medicine found that aerobic exercise can lead to more rest at night for people who suffer from existing sleep problems, but only if they maintain an exercise regimen for roughly four months.

Studies have long suggested that aerobic exercise can contribute to better sleeping habits. But much of the research on the daily effects of exercise on sleep was conducted with healthy sleepers. The new study, by contrast, looked at the long-term effects of exercise in people already suffering from sleep disorders.