The purpose of the resurrection is clear: to rebuild the body free of any impurities, when it is more soul-like than body-like. The time of resurrection will vary, one who is rectified earlier from his impurity will die and resurrect earlier. The period of death to resurrection for the entire 'generation' will be long, though, tzaddikim who have died previously will resurrect immediately at the beginning of the period, which will be after forty years of the ingathering of the exiles.
There will be many resurrections over a large period of time, with the first resurrection occurring after forty years of ingathering of exiles, that is, 210 years in advance of Year 6000. The last resurrection will occur towards the end of the 210 years. During that period, some people will have already resurrected, whereas others will still await death, decomposition, and, resurrection.
It says in the Zohar HaKadosh that resurrection will take 210 years and be complete before the year 6,000.
1. First resurrection will take place in Eretz Israel (in the year 2,030)
2. In the diaspora
3. The non-Jews that kept 7 Mitzvot of Bnei Noach and those that did good deeds to the Jews.