code: public static Object waitForAppearanceInJNDI(final Context ctx, final String jndiName, long timeout) {
          while (timeout > 0) {
              try {
                  Object result = ctx.lookup(jndiName);
                  if (result != null) {
                      return result;
                  }
              } catch (NameNotFoundException ignored) {
              } catch (NamingException ex) {
                  throw new RuntimeException("Failed JNDI lookup for " + jndiName, ex);
              }
  
              try {
                  Thread.sleep(10);
              } catch (InterruptedException ex2) {
                  throw new RuntimeException("Interrupted while doing JNDI lookup for " + jndiName);
              }
  
              timeout -= 10;
          }
  
          return null;
      }
docs: this can't be recursive, as it can blow the stack