Former NASA astronaut José Hernández knows something about living in tight quarters and being pretty isolated — something he learned long before the coronavirus pandemic forced so many around the globe to do just that.

Hernández, 57, did in 2009 what many dream of doing: He went to space as a mission specialist on the STS-128 Discovery shuttle that flew to the International Space Station.

He says his training for that mission keeps him sane and focused these days, and it can help others, as well.

"The life of the astronaut is isolating even for a short mission of two weeks in space. We were in medical isolation for weeks prior, because you don't want to go home and then get sick and risk the mission," Hernández told NBC News. "So we're well over a month in isolation, and even before that, you go do a lot of exercises in small groups with your team."

Full coverage of the coronavirus outbreak

Getting ready to go to space included survival training, such as how to live in the mountains in the middle of winter. In a forest in Maine, the astronauts-in-training were given no food or water and had to figure it out. "We had to see what the forest would give us, so you do fishing, you go find water. It was a way to bring cohesiveness to the group and work together," he says.

Another training exercise involved living in a module 60 feet underwater to mirror what it was like being in space.

All that helped him cope and develop a strategy for being by himself and keeping a positive attitude.

"You have to look at the glass half-full, not half-empty," he says. Hernandez recalls the time he complained about something during a training session and his commander said "hey, you're one of 500 people" who ended up with the privilege of going up in space. That, Hernández says, put it in perspective.

Not that the coronavirus isn't scary, Hernández says, but you try to make the best of even a bad situation.

Communicate, keep a schedule

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

"The positive here is we are with our families, we are with our loved ones," Hernández says. "You're spending more time with those you wouldn't ordinarily be with all the time, so make the best of it."

In a confined, crowded environment, as it can be for many who are quarantining with their families, good communication is key, particularly when tension runs high and patience runs low.

He recommends a technique NASA used as a safety procedure: Say something more than once, and get confirmation.

"What I have found is that it's probably good to repeat when you communicate with others, because it allows you to hear what you have told the other person, and when that other person repeats it to you, you hear what you said, and it filters out unreasonable requests, for example," Hernández says. "That way you can defuse situations that could escalate."

He uses another NASA technique — creating a schedule and sticking to it.

"Even for those who are not working right now, having a schedule down to the hour helps quantify your day and allows you to have a little bit of fulfillment and that you accomplished something," he says. "You can claim small victories."

Download the NBC News app for full coverage and alerts about the coronavirus outbreak

Hernández recognizes that not everyone can be with their families and that some are by themselves during the pandemic. Making a concerted effort to be connected, as he did during his time at NASA, helps stem the pangs of loneliness and isolation.

"It's hard to train to be away from your loved ones. But technology helps," he says, recalling his many chats with his family via video. "I'd entertain my kids by floating M&Ms and eating them, and nowadays I still use technology a lot."

Although Hernández's parents live only 10 minutes away, they're communicating via phone and computer video. "Because of their age, I don't want to risk them getting sick, so we 'see' them and talk with them on video. Just because you're isolated doesn't mean you can't communicate with your loved ones."

Jose Hernandez, left, with Leticia, his sister, and Gil, his brother. Courtesy Jose Hernandez

Hernández, an engineer who left NASA in 2011, is the son of migrant farmworkers from Mexico. Now a consultant and an author, he has gone back to his farming roots and started a small vineyard in his hometown, Stockton, California.

When he was growing up, Hernández helped his family pick crops. He has a deep appreciation for agricultural workers out in the fields during the pandemic.

"Thanks to them I'm able to feed my family during this scary situation," Hernández says.

U.S. farmworkers are considered "essential workers," but workers and advocates worry that they're not being sufficiently protected at this time.

These images from the immigrant farmworker appreciation caravan in California make my heart sing. pic.twitter.com/zVzbTgqN1o — Daniel Altschuler 🦋 (@altochulo) April 20, 2020

In Washington state, two unions representing agricultural workers, the United Farm Workers of America and Familias Unidas Por La Justicia AFL-CIO, sued the state (specifically the Health Department) seeking safer working conditions during the crisis.

"We should make sure that our farmworkers day in and day out have the proper personal protection equipment given the conditions they're asked to work in," Hernández says.

Follow NBC Latino on Facebook, Twitter and Instagram.