Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to terminate Firebase thread in Spring MVC app

I am using Firebase in a Spring MVC app in tomcat. It seems firebase creates a non-daemon thread that prevents tomcat from shutting down.

How do I terminate/shutdown Firebase in my Spring app?

This is how I am using Firebase:

private static Firebase getUserRef(String username)
{
    Firebase ref = new Firebase("https://<firebaseurl>"); 
    return ref.child(username);
}
private static void createUserName(final String name)
{
    final Firebase userref = getUserRef(name);
    userref.addListenerForSingleValueEvent(new ValueEventListener()
    {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot)
        {
            Object value = dataSnapshot.getValue();
            // logic
        }

        @Override
        public void onCancelled(FirebaseError firebaseError)
        {

        }
    });
}

The createUserName() method is called inside a controller method.

Should I be using beans?

like image 490
pdeva Avatar asked Dec 28 '13 19:12

pdeva


1 Answers

This issue has been fixed as of v1.0.15 of the Firebase Java Client. You can download the latest version here: https://www.firebase.com/docs/java-quickstart.html

Firebase now creates only daemon threads, so your process will exit cleanly as expected.

like image 95
Andrew Lee Avatar answered Sep 30 '22 15:09

Andrew Lee