utils/AppUtils.java: Added waitForLock()

 * Added two static waitForLock functions which
   implements basic sleep and check locking.

 * Converted old code to use new functions