Search code examples
visual-studio-codewar

vscode-tomcat stopping issue


I debug war on vscode tomcat extension and it works fine. The issue is when I try to stop tomcat, it throws some error and not stop and shows always green. enter image description here

java pid shows tomcat still running. When I pkill java process then vscode-tomcat goes red.

apache-tomcat-9.0.34 ps aux | grep java

snb 93854 100.0 2.1 10618536 353492 ?? R 10:41PM 49:07.67 /usr/bin/java -agentlib:jdwp=transport=dt_socket,suspend=n,server=y,address=localhost:8000 -classpath /Users/snb/opt/apache-tomcat-9.0.34/bin/bootstrap.jar:/Users/snb/opt/apache-tomcat-9.0.34/bin/tomcat-juli.jar -Dcatalina.base=/Users/snb/Library/Application Support/Code/User/workspaceStorage/67a9c0d6ca9a41f8deff20583f3e36ec/adashen.vscode-tomcat/tomcat/apache-tomcat-9.0.34 -Dcatalina.home=/Users/snb/opt/apache-tomcat-9.0.34 -Dfile.encoding=UTF8 -Djava.io.tmpdir=/Users/snb/Library/Application Support/Code/User/workspaceStorage/67a9c0d6ca9a41f8deff20583f3e36ec/adashen.vscode-tomcat/tomcat/apache-tomcat-9.0.34/temp org.apache.catalina.startup.Bootstrap start

How can I solve this issue


Solution

  • You can use @PreDestroy annotation.

    The @PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container.

    @Component
    public class UserRepository {
    
        private DbConnection dbConnection;
        @PreDestroy
        public void preDestroy() {
            dbConnection.close();
        }
    }