Tomcat 8 websocket example
If there is a SCI with a annotation, Tomcat has to scan your application for classes that use annotations or interfaces specified in that annotation. The metadata-complete option is not enough to disable all of annotation scanning. Setting metadata-complete="true" disables scanning your web application and its libraries for classes that use annotations to define components of a web application (Servlets etc.). Set metadata-complete="true" attribute on the element.There are two options that can be specified in your WEB-INF/web.xml file: In Tomcat 8 the TLD scanning happens only once at startup time (in JasperInitializer). The second scanning is more noticeable, because it prints a diagnostic message about scanned JARs that contained no TLDs.
#Tomcat 8 websocket example code
second, by JSP engine when generating java code for a JSP page (done by TldLocationsCache).first, at startup time, to discover listeners declared in tld files (done by TldConfig class),.If you do not need support for WebSockets, you may remove the WebSocket API and WebSocket implementation JARs from Tomcat ( websocket-api.jar and tomcat7-websocket.jar or tomcat-websocket.jar).Ī note on TLD scanning: In Tomcat 7 and earlier the TLD scanning happens twice, An SCI class declared there triggers scanning for WebSocket endpoints (the classes annotated with or implementing ServerApplicationConfig interface or extending the abstract Endpoint class). That is because each class file (except ones in ignored JARs) has to be read and parsed looking for annotations in it.Īn example of a container-provided SCI that triggers annotation scanning is the WebSocket API implementation which is included with standard distribution in all versions of Tomcat 8 and with Tomcat 7 starting with 7.0.47. Scans for Tag Library Descriptor files, META-INF/**/*.tld).Īmong the scans the annotation scanning is the slowest. TLD scanning, (Discovery of tag libraries.Older features, introduced by earlier specifications: Annotations that define components for 3-rd party libraries initialized by an SCI (arbitrary annotations that are defined in annotation on a SCI class).Annotations that define components of a web application ( etc.).Resources of a web application bundled in jar files ( META-INF/resources/*).
Conformance to the specification requires that the scanning were performed by default, but you can configure your own web application in several ways to avoid it (see below). Unfortunately, these features require scanning of JAR and class files, which may take noticeable time. Those exist to simplify a structure of a web application and to simplify plugging of additional frameworks. The Servlet 3.0 specification (chapter 8) introduced support for several "plugability features". See Troubleshooting and Diagnostics page for details. That is to take several thread dumps to see what Tomcat is really doing. Generalīefore we continue to specific tips and tricks, the general advice is that if Tomcat hangs or is not responsive, you have to perform diagnostics.
#Tomcat 8 websocket example how to
This section provides several recommendations on how to make your web application and Apache Tomcat as a whole to start up faster.