javaunohelper: More robust way to wait for finalization

Change-Id: I09fa2462d8131381f380574b8a9aeaf080211b2b
Reviewed-on: https://gerrit.libreoffice.org/11759
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>