lundi 4 janvier 2016

Java Service gets hung when stopping

I have created a Java windows service using procrun. When I try to stop the service it gets hung. Below shown is my stop method implementation.

private static void stopPlugins() {
    LOGGER.log(Level.INFO, "Came inside stop plugins method");
    for (Class cl : classes) {
        LOGGER.log(Level.INFO, "The class that has been loaded is : " + cl);
        try {
            Method m = cl.getDeclaredMethod("stop");
            Object o = classMessageListenerMap.get(cl);
            o = m.invoke(o);
            LOGGER.log(Level.INFO, "Stop method has been invoked for : " + cl);
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}

I have loaded some Jars through reflection in my service. So when stop method of the service is called, I call the "stop" methods of those jars. But it always gets hung when calling the "stop" method of the last jar. I have changed this last jar several times putting different jars to be the last ones. But they all get hung. But when I put "System.exit(0)" instead of calling the stop methods of each jar, it does terminate the service without any issue. I went to this method since some have said System.exit to be a bad practice. Why is this implementation causing issues? When I execute this method through code, all jars execute successfully. Its just this service that is causing issues. Please advice.





Aucun commentaire:

Enregistrer un commentaire