The greatest influx of people into Europe in decades is not just a humanitarian emergency, but also a potential stroke of luck for many countries facing the economic threat of an aging population.

A plunge in birth rates means there will be a dearth of European workers in coming years to support the growing number of retirees. So the arrival of thousands of young — and often well-educated — potential workers stands to boost the long-term economic prospects of the region.

The key is how well they are integrated and how many jobs European countries can offer.

Germany, among the most vocal in welcoming refugees, is also conveniently the country that stands to gain most quickly, as it has a strong labor market with lots of vacancies.

By contrast, weaker economies like Greece and Italy will take years, even decades, to see positive effects as they struggle to create jobs — though they too face the threat of a demographic time bomb.

"Let us not forget, we are an aging continent in demographic decline," the president of the European Union Commission, Jean-Claude Juncker, said last month in a speech. "We will be needing talent."

Before the influx of people began this year, the German statistics office said it expected the country's population, now 80.8 million, to shrink by a tenth or more by 2060. Germany forecasts its workforce will drop by 6 million in the next 15 years.

Welcoming an estimated 800,000 people from Syria, Iraq and other countries this year will cost Germany about 6 billion euros ($6.6 billion) next year in welfare support and language training.

But such upfront costs may be recouped through higher economic growth. Andreas Rees, economist at UniCredit bank, estimates that the flood of new arrivals over the next few years could grow Germany's economy by an extra 1.7 percent by 2020.

Daimler CEO Dieter Zetsche, whose German company makes Mercedes-Benz cars and trucks, made the case this week: "To take into Germany more than 800,000 people who need our help is without a doubt a Herculean task, but in the best case, it can also be the basis for the next German economic miracle."

Sweden, which last year received 80,000 asylum seekers, second highest in the EU behind Germany, also views the newcomers as a net gain, though up-front costs may be stiff. "Because we have an aging population," Kristina Persson, minister for Nordic cooperation, said, "we have to replace those who leave the labor market."

That may not be so easy in other countries. Greece, which is the first EU country of arrival for many people travelling from the Middle East, has an unemployment rate near 25 percent, with about half of young people out of work. It is expected to take a generation to turn the economy around.

And the new arrivals know it, preferring to move on to try to reach Germany and the richer countries of Northern Europe.

Ironically, some of the countries in Europe that are most threatened by a drop in birth rates are working the hardest to keep newcomers out.

Hungary is one such case. It is sealing its borders with barbed wire and firing tear gas and water cannons to keep migrants away.

In Poland, a shift to smaller-size families years ago means fewer workers now support each retiree, a trend expected to worsen dramatically over the next two decades. So far, Poland has agreed to accept 2,000 refugees. It is considering increasing the number slightly, but has rejected an EU request that it take 12,000.

And the Czech government has barely cracked its door open, allowing in just 1,500 migrants, despite a demographic drag on its own economy. In 25 years, the country is expected to go from having four people of working age supporting each person 65 or older, down to two.

Overall, the politics of welcoming refugees and other migrants is influenced more by cultural and political factors than economic ones — even in Germany.

Germany's economy could benefit from an even greater increase in immigration, experts say, but the government is hesitant. Chancellor Angela Merkel has said that foreigners fleeing war or persecution are welcome, but those who have come solely for economic reasons, "must leave our country."

Some states, including Poland, are worried not only about the immediate costs of welcoming refugees, but are also mindful of popular fears that foreign-born Muslims might not easily blend into society or that terrorists could lurk among them.

A migration expert at the Organization for Economic Cooperation and Development in Paris, Jean-Christophe Dumont, said that it's costlier up front to integrate refugees than other categories of immigrants, because they often need language and vocational training as well as treatment for physical injuries or psychological trauma.

However, refugees, if well integrated, ultimately have a positive impact on the economy, Dumont said. One Australian study found that within 15 years, humanitarian migrants contribute more to their new country of residence than they cost it in benefits.

Ulrich Grillo, head of the Federation of German Industries, has said the German government needs to ensure the refugees now arriving are quickly permitted to work. Already, some companies have indicated their willingness to take on some of the newcomers, with Siemens and Deutsche Telekom offering a small number of paid internships.

McDonald's Germany has said it would help the government provide 20,000 online language courses for asylum-seekers.

Zetsche, Daimler's CEO, has been among the most bullish about the migrants' positive impact, saying at the Frankfurt auto show this week that anyone who has managed to surmount the obstacles to make it to Germany from the Middle East or Africa has obviously got what it takes to work for him.

"I believe anybody who leaves their life completely behind will be highly motivated to learn and work here, and to build a new life," said Zetsche. "We are looking for exactly this type of person at Mercedes, and everywhere in our country."

___

Condon reported from New York. David Rising and Geir Moulson in Berlin, Vanessa Gera in Budapest, Karel Janicek in Prague, Alison Mutler in Bucharest, Barry Hatton in Lisbon and Karl Ritter in Stockholm contributed.