Contact sync openfire with my contacts list

Hello everyone, I want to make a contact sync service for my chat application. I have some of contacts who are register in openfire. I want to fetch that person separately. I did some funny way of things such as i get the all contacts from openfire and then compare with my local contacts list. if both are same i’ll be show that list in my app. But, it was wrong way because it’s take more time for sync at that moment app will be freeze or crash. If anybody know how to come back that issue. Please let me know.

Advance thanking you.