Does the word "stretch" have the same definition in the next two sentences?

He did a stretch in the federal penitentiary.

There were stretches of boredom.
the same meaning