A gunman who killed 10 people at a school in Finland wrote handwritten notes saying he hated humankind, and that he had been planning the attack since 2002.

The gunman, who fatally shot himself after the rampage Tuesday, was a trainee chef at the vocational institute in Kauhajoki, about 300 kilometres northwest of Helsinki.

Police have identified him as 22-year-old Matti Juhani Saari.

He left notes at the school's dormitory saying he despised the human race and the only solution was a "Walther 22," a .22-calibre pistol he used in the shooting spree.

Saari had also left violent YouTube postings and police had questioned him about the videos just one day before the attack.

Police say Saari, dressed in black and carrying a large bag, entered the school around 11 a.m. local time and opened fire on a class of students writing an exam.

"I heard several dozen rounds of shots, in other words it was an automatic pistol," school janitor Jukka Forsberg told Finnish broadcaster YLE. "I saw some female students who were wailing and moaning and one managed to escape out the back door."

Nine people died at the scene and a woman who was taken to hospital with a head wound died later.

Between 150 and 200 students were in the building at the time.

Saari's YouTube video showed him firing a handgun and included the message: "Whole life is war and whole life is pain. And you will fight alone in your personal war."

Journalist Leo Pugin told ۴ýnet that the video was uploaded on Friday.

"After questioning this man police decided not to do any further measures," Pugin said from the capital, Helsinki.

"There was no direct threats in the video. He was just shooting."

Gun ownership in Finland is among the highest in the world, behind only the U.S. and Yemen.

The gunman may have been imitating a November, 2007 shooter in Finland. In that incident, an 18-year-old man killed five boys, two girls and the female principal at a high school in Tuusula, about 50 kilometres north of Helsinki.

He then turned the gun on himself and died later in hospital, according to officials.

The 2007 shooter, identified by police as Pekka-Eric Auvinen, who was a student at the school, posted video foreshadowing the attack on the popular video-sharing website.

With files from The Associated Press