Clarifications on Tomcat's "temp" and "work" directories
Asked Answered
M

2

38

I have been using Tomcat for quite a while now but I am not sure what the

  • "temp" and
  • "work"

directories are used for and when I need to clean which.

Can anyone please advise?

Mortgagor answered 13/1, 2012 at 15:59 Comment(0)
M
40
  • work stores compiled JSPs and other assets.
    => You only need to "clean" the webapp directories under it on the rare occasions when an update to a WebApp is not picked up.

  • temp is used to store files created using the Java File API for creating temporary files.
    => You can "clean" it every time you restart Tomcat. If it is getting too full then one of your WebApps may have some form of leak where its not releasing temp files when its done with them (although it could just be under higher load too).

Maniemanifest answered 13/1, 2012 at 16:4 Comment(3)
Robert: thanks! Can you tell me under which directory the session data is stored?Mortgagor
@Mortgagor session data is in-memory, isn't it?Dismay
@adarsh not persistent session data though.Mortgagor
S
1

Addressing the temp files not being cleaned after restart.

<Host name="localhost" appBase="webapps">
    <Context docBase="mywebapp" path="/mywebapp">
        <LifecycleListener className="org.apache.catalina.startup.ContextConfig"
            <Parameter name="clearReferencesStopThreads" value="true" />
        </LifecycleListener>
    </Context>
</Host>

The configuration you added to the server.xml file will enable Tomcat's cleanup mechanism to remove temporary files in the /opt/tomcat/temp directory. This is a valid way to address the issue of accumulated temporary files.This solved the issue for me. Make sure it is affecting your desired webapp.

Also can someone please specify the possible reasons why these files are not getting cleaned? I am facing the same issue where temp files are not being cleaned up after tomcat restart. I am trying to find the solution other than adding the configuration.

Somnambulism answered 16/3, 2023 at 12:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.