×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / java.lang.outOfMemoryError
    Java program, unlike C program will swap to virtual memory if out of
    physical memory. Java only allocate a block of physical memory for
    JVM to run application.

    I have a servlet that will receive pretty heavy http request. There
    will be a chance of OutOfMemory Error if it receives too many request
    at a time.

    Any good way I can prevent OutOfMemoryError to happen? Since If the
    JVM throws an OutOfMemroyError, that means JVM is crashed and it will
    no longer function correctly until I restart the JVM (servlet engine)
    I think.

    What I am thinking to do is to set a upperbound memory usage in my
    servlet, If servlet find out JVM is almost out of the memory, It will
    block(stop process) anymore client request and just return an error
    code like --> server busy something like that. That will prevent
    servlet crash the VM.

    I wonder if there is any better way? except calling gc().

    Thanks.
    • with you method, you can also enlarge the heap of engine
    • You must release some objects if you don't want use them anymore,and gc will do something automatically