As'as bin Salamah (may Allah be pleased with him) states that the Prophet (peace and blessings be upon him) was on a journey and found one of his companions missing. He was then brought, and he said: I want to keep away from people and occupy myself with the worship of Allah. He (peace and blessings be upon him) said: "Do not do that, and let none of you do that." He (peace and blessings be upon him) said this three times, then said: "To be patient for a single hour in the gatherings of the Muslims is better than forty years of worship in solitude."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20176