Just days before he was shot and killed, a Baton Rouge police officer posted an emotional Facebook message saying he was “physically and emotionally” tired and expressing how difficult it was to be both a police officer and a black man, a friend has said.

“I swear to God I love this city but I wonder if this city loves me,” Montrell Jackson wrote on Sunday.

Friends and family of Jackson, 32, were mourning the 10-year-veteran of the police force that relatives described as a “gentle giant” and a “protector” after he and another two law enforcement officers were shot and killed on Sunday morning by a gunman.

Sgt. Don Coppola Jr. of the Baton Rouge Police Department identified the other slain Baton Rouge police officer as 41-year-old Matthew Gerald, who had been with the department less than a year.

The third officer killed was 45-year-old sheriff’s deputy Brad Garafola, a 24-year veteran, spokeswoman Casey Rayborn Hicks for the East Baton Rouge Parish Sheriff’s Office said.

In the Facebook posting Jackson said while in uniform he gets nasty looks and out of uniform some consider him a threat.

“I’ve experienced so much in my short life and these last 3 days have tested me to the core,” the posting read.

The message was posted on July 8, just three days after a black man was shot and killed by police in Baton Rouge. That shooting was the beginning of an extremely tense week in the country’s fraught history of race relations.

Another black man was shot and killed by police the next day in Minnesota, with his girlfriend livestreaming the aftermath on Facebook. Then a black gunman opened fire during a protest against the police shootings in Dallas, killing five police officers.

Jackson does not specifically refer to those events but the posting appears to be a reaction to them.

Erika Green told The Associated Press on Sunday that she is friends with the family of Jackson, one of three Baton Rouge law enforcement officers who were killed on Sunday morning. She said she saw the message on his Facebook page.

In the message, Jackson says he is physically and emotionally tired.

“These are trying times. Please don’t let hate infect your heart,” Jackson wrote.

A screenshot of the image has been widely circulating on the internet but is no longer on Jackson’s Facebook page.

Jackson’s family was mourning the officer on Sunday afternoon.

Kedrick Pitts, the 24-year-old younger half brother of Montrell Jackson, said he was very close to his older brother.

“With him it was God, family and the police force,” Mr. Pitts said outside his mother’s house in Baton Rouge, where family was gathered yesterday. “He went above and beyond ... He was a protector,” he added.