title: Firebase DatabaseReference CompletionListener is not getting called
body: <p>I have a Java non-android application, it is a wicket application, is created as Dynamic Web Project in eclipse and i am running it with tomcat. I want to connect to Firebase Realtime Database from this application and after researching a lot it seems that because the app is running in the main thread it doesn't call the completion listener. Here is my code.</p>
  <pre><code>public class StatusButton extends Link&lt;Void&gt; {
  public StatusButton(String id) {
          super(id);
  }
  @Override
      public void onClick() {
          
          Firebase firebase = new Firebase();
          firebase.update(&quot;TestInput&quot;, &quot;Users&quot;);
      }
  }
  
  public class Firebase {
  
      private static final String DATABASE_URL = &quot;https://mydatabase.firebaseio.com/&quot;;
      private FirebaseDatabase firebaseDatabase;
  
      public Firebase() {
          InputStream serviceAccount = this.getClass().getResourceAsStream(&quot;/serviceAccountKey.json&quot;);
          try {
              FirebaseOptions options = new FirebaseOptions.Builder()
                  .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                  .setDatabaseUrl(DATABASE_URL)
                  .build();
              if(FirebaseApp.getApps().isEmpty()) {
                  FirebaseApp.initializeApp(options);
              }
              firebaseDatabase = FirebaseDatabase.getInstance(DATABASE_URL);
      }
  
      public void update(Object value, String key) {
              DatabaseReference ref = firebaseDatabase.getReference(key);
              readData(value,ref), new OnGetDataListener() {
                  @Override
                  public void onSuccess(DataSnapshot dataSnapshot) {
                      System.out.println(&quot;On Success &quot;+ dataSnapshot);
                  }
                  @Override
                  public void onStart() {
                      System.out.println(&quot;ONSTART&quot;);
                  }
                  @Override
                  public void onFailure() {
                      System.out.println(&quot;ON Failure&quot;);
                  }
              });
          } catch (IOException ioe) {
              System.out.println(ioe.getMessage());
          }
  }
  
  public void readData(Object value, DatabaseReference ref, final OnGetDataListener listener) {
          listener.onStart();
          try {
              final CountDownLatch latch = new CountDownLatch(1);
              ref.setValue(value, new DatabaseReference.CompletionListener() {
                  @Override
                  public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                      if (databaseError != null) {
                          System.out.println(&quot;Data could not be saved &quot; + databaseError.getMessage());
                      } else {
                          System.out.println(&quot;Data saved successfully.&quot;);
                      }
                      latch.countDown();
                  }
              });
          latch.await();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  
  public interface OnGetDataListener {
      //make new interface for call back
      void onSuccess(DataSnapshot dataSnapshot);
      void onStart();
      void onFailure();
  }
  </code></pre>
  <p>The problem is that the code never goes into onComplete method so i cannot have any interaction with the Firebase. Any help will be appreciated.</p>