Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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) {
        } catch (SecurityException e) {
        } catch (IllegalAccessException e) {
        } catch (IllegalArgumentException e) {
        } catch (InvocationTargetException e) {

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900