Search code examples
javaapachetomcatweb-applicationsweb-inf

Slow Tomcat Webapp start when lots of files in WEB-INF


I've got a Webapp with a lot of files under the WEB-INF folder (1000s). When it starts or restarts it takes a long time > 10s even with Jar and TLD scanning turned off. I even created a custom JarScanner class that does nothing which made no difference.

What else in Tomcat scans that folder when a context is started and can I do anything about it?


Solution

  • If you have these files directly in the WEB-INF folder (or just in a single one), the OS might take its time to make sense of the folder. 1000s of files in a single folder are not handled well by many operating systems. Thus it might not scan anything, but just open the directory.

    What OS are you on? You might also want to try to keep a zipped WAR file instead of "exploding" the whole webapplication directory? This can by done by setting the unpackWARs attribute of the <Host> element in server.xml if I remember correctly:

    <Host name="localhost" unpackWARs="false" ...>
    

    Also, try to separate the files into many different folders, or, even better, outside of the webapplication directory. Especially if they're just data files, it might be easier to keep them away from tomcat.

    And lastly, as a reply to your comment, this might tell you that you've successfully traded startup time for ease of maintenance (as you state that files are easier to maintain)