Vaadin 8 + Tomcat

Hi!

When I stop the application from tomcat before undeploying I have this exception:

gen 05, 2018 6:48:24 PM com.vaadin.event.ListenerMethod writeObject
AVVERTENZA: Error in serialization of the application: Class com.actuaria.actuarianet.core.utils.sistema.ActuariaUIServlet$1$1 must implement serialization.
gen 05, 2018 6:48:24 PM org.apache.catalina.session.StandardSession writeObject
AVVERTENZA: Cannot serialize session attribute com.vaadin.server.VaadinSession.ActuariaUIServlet for session 4F4B54715B8DE09958D387312C367039
java.io.NotSerializableException: org.apache.catalina.loader.WebappClassLoader
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
        at com.vaadin.event.ListenerMethod.writeObject(ListenerMethod.java:91)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at java.util.HashSet.writeObject(HashSet.java:287)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
        at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
        at com.vaadin.server.VaadinSession.writeObject(VaadinSession.java:1484)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1028)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
        at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1695)
        at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:1101)
        at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:430)
        at org.apache.catalina.session.StandardManager.unload(StandardManager.java:351)
        at org.apache.catalina.session.StandardManager.stopInternal(StandardManager.java:516)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5683)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        at org.apache.catalina.manager.ManagerServlet.stop(ManagerServlet.java:1336)
        at org.apache.catalina.manager.HTMLManagerServlet.stop(HTMLManagerServlet.java:713)
        at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:219)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:612)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

Here my servlet

@WebServlet(urlPatterns = "/*", name = "ActuariaUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = ActuariaUI.class, productionMode = false, closeIdleSessions = true)
public class ActuariaUIServlet extends VaadinServlet {

    private static final long serialVersionUID = 7833885329138452265L;

    @Override
    protected void servletInitialized() throws ServletException {
        super.servletInitialized();
        getService().addSessionInitListener(new SessionInitListener() {
            
            private static final long serialVersionUID = 7388370837180101583L;

            public final void sessionInit(final SessionInitEvent event) throws ServiceException {
                event.getSession().setLocale(ActuariaMessages.getCurrentLocale());
                event.getSession().addBootstrapListener(new BootstrapListener() {
                    private static final long serialVersionUID = 4749319307867273003L;

                    @Override
                    public void modifyBootstrapPage(final BootstrapPageResponse response) {
                        final Element head = response.getDocument().head();
                        head.appendElement("meta")
                                .attr("name", "viewport")
                                .attr("content",
                                        "width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes");
                        head.appendElement("meta")
                                .attr("name", "apple-mobile-web-app-capable")
                                .attr("content", "yes");
                        head.appendElement("meta")
                                .attr("name", "apple-mobile-web-app-status-bar-style")
                                .attr("content", "black-translucent");
                        head.appendElement("meta")
                                .attr("name", "theme-color")
                                .attr("content", "#ffffff");

                        String contextPath = response.getRequest().getContextPath();
                        head.appendElement("link")
                                .attr("rel", "apple-touch-icon")
                                .attr("sizes", "180x180")
                                .attr("href", contextPath + "/VAADIN/themes/actuariatheme/img/apple-touch-icon.png");

                        head.appendElement("link")
                                .attr("rel", "icon")
                                .attr("sizes", "32x32")
                                .attr("type", "image/png")
                                .attr("href", contextPath + "/VAADIN/themes/actuariatheme/img/favicon-32x32.png");

                        head.appendElement("link")
                                .attr("rel", "icon")
                                .attr("sizes", "16x16")
                                .attr("type", "image/png")
                                .attr("href", contextPath + "/VAADIN/themes/actuariatheme/img/favicon-16x16.png");

                        head.appendElement("link")
                                .attr("rel", "icon")
                                .attr("sizes", "192x192")
                                .attr("type", "image/png")
                                .attr("href", contextPath + "/VAADIN/themes/actuariatheme/img/android-chrome-192x192.png");

                        head.appendElement("link")
                                .attr("rel", "manifest")
                                .attr("href", contextPath + "/VAADIN/themes/actuariatheme/img/manifest.json");
                        head.appendElement("link")
                                .attr("rel", "mask-icon")
                                .attr("color", "#1f497d")
                                .attr("href", contextPath + "/VAADIN/themes/actuariatheme/img/safari-pinned-tab.svg");
                    }

                    @Override
                    public void modifyBootstrapFragment(final BootstrapFragmentResponse response) {
                    }
                });
            }
        });
        getService().setSystemMessagesProvider(new ActuariaSystemMessagesProvider());
    }

    @Override
    protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
        VaadinServletService servletService = new VaadinServletService(this, deploymentConfiguration) {
            private static final long serialVersionUID = 2022740869875760876L;

            @Override
            public void requestStart(VaadinRequest request, VaadinResponse response) {
                super.requestStart(request, response);
                HttpServletRequest req = (HttpServletRequest) request;
                Object idUtente = req.getSession().getAttribute("idUtente");
                MDC.put("idUtente", idUtente != null ? idUtente : "");
                String userAgentInfo = request.getHeader("User-Agent");
                String remoteAddress = request.getRemoteAddr();
                MDC.put("remoteIpAddress", remoteAddress);
                MDC.put("userAgentInfo", userAgentInfo);
            }

            @Override
            public void requestEnd(VaadinRequest request, VaadinResponse response, VaadinSession session) {
                super.requestEnd(request, response, session);
                MDC.clear();
            }
        };
        servletService.init();
        return servletService;
    }
}

Could someone help me to find where is the bug, please? Thanks

Do you really need to serialize session at shutdown of Tomcat? Normally this is not needed, and this exception is harmless. If you want to supress it you could disable the serialization during shutdown in server.xml config file with something like this:

Thank you! I have to put it in context.xml and that exception is gone.

But I have also other exceptions at shotdown


gen 06, 2018 11:53:36 AM org.atmosphere.util.ForkJoinPool <init>
INFORMAZIONI: Using ForkJoinPool  java.util.concurrent.ForkJoinPool. Set the org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads to -1 to fully use its power.
gen 06, 2018 11:53:36 AM org.atmosphere.cpr.DefaultBroadcaster addAtmosphereResource
AVVERTENZA: AtmosphereResource b4a9e024-4607-4eb9-af1c-f71c0d030893 is not suspended. If cached messages exists, this may cause unexpected situation. Suspend first
gen 06, 2018 11:53:36 AM org.atmosphere.cpr.DefaultBroadcaster addAtmosphereResource
AVVERTENZA: AtmosphereResource 6f967901-1e79-4c7e-b25a-50e7b468a1e9 is not suspended. If cached messages exists, this may cause unexpected situation. Suspend first
06-Jan-2018 11:53:36.187 AVVERTENZA [http-nio-8080-exec-20]
 org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [actuarianet-0.0.1-SNAPSHOT]
 registered the JDBC driver [com.mysql.jdbc.Driver]
 but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
06-Jan-2018 11:53:36.188 AVVERTENZA [http-nio-8080-exec-20]
 org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [actuarianet-0.0.1-SNAPSHOT]
 appears to have started a thread named [Abandoned connection cleanup thread]
 but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
06-Jan-2018 11:53:36.189 AVVERTENZA [http-nio-8080-exec-20]
 org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [actuarianet-0.0.1-SNAPSHOT]
 appears to have started a thread named [Atmosphere-Scheduler-0]
 but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:1134)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
06-Jan-2018 11:53:36.190 AVVERTENZA [http-nio-8080-exec-20]
 org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [actuarianet-0.0.1-SNAPSHOT]
 appears to have started a thread named [Atmosphere-Shared-0]
 but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
 org.atmosphere.cpr.DefaultBroadcaster$1.run(DefaultBroadcaster.java:405)
 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 java.util.concurrent.FutureTask.run(FutureTask.java:266)
 java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
 java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
 java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
 java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
 java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
06-Jan-2018 11:53:36.191 AVVERTENZA [http-nio-8080-exec-20]
 org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [actuarianet-0.0.1-SNAPSHOT]
 appears to have started a thread named [Atmosphere-Scheduler-1]
 but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:1129)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
06-Jan-2018 11:53:36.192 AVVERTENZA [http-nio-8080-exec-20]
 org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [actuarianet-0.0.1-SNAPSHOT]
 appears to have started a thread named [Resource Destroyer in BasicResourcePool.close()]
 but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.net.DualStackPlainSocketImpl.shutdown0(Native Method)
 java.net.DualStackPlainSocketImpl.socketShutdown(DualStackPlainSocketImpl.java:172)
 java.net.AbstractPlainSocketImpl.shutdownInput(AbstractPlainSocketImpl.java:567)
 java.net.PlainSocketImpl.shutdownInput(PlainSocketImpl.java:254)
 java.net.Socket.shutdownInput(Socket.java:1526)
 com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:2246)
 com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4236)
 com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1462)
 com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:642)
 com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:255)
 com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:622)
 com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:1076)
 com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1101)
 com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1062)
 com.mchange.v2.resourcepool.BasicResourcePool.access$100(BasicResourcePool.java:44)
 com.mchange.v2.resourcepool.BasicResourcePool$5.run(BasicResourcePool.java:1316)
06-Jan-2018 11:53:40.349 INFORMAZIONI [Abandoned connection cleanup thread]
 org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
 java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
        at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)
        at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:986)
        at com.mysql.jdbc.AbandonedConnectionCleanupThread.checkContextClassLoaders(AbandonedConnectionCleanupThread.java:90)
        at com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:63)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

I use Tomcat 8.5.24.