java - How does a servlet handle more bytes than available RAM? -


lets have servlet running accepts files of size client application(s). file being sent loaded datahandler , transmitted web-services; such received , put datahandler. happens if file being sent exceeds size of available ram on receiving host?

my initial thoughts are:

1)the jvm put in virtual memory, size of file been known through header messages , jvm sneaky , allocate space ahead of time. however, did not think virtual memory space big.

2)the jvm create "hidden" file hold data on hard disk , datahandlers output stream load data ram needed.

in either case seems easier write file hard disk anyway avoid using data after receive it. server hosting servlet have many different clients sending large files around same time , wondering how jvm handle issues this.

the servlet api provides streams on request , response. input stream on request load bytes jvm required.

the stream not hold data in memory, call read() gets data out of small buffer or causes blocking read on socket. application try read whole, large, stream byte array or other data structure, run out of memory.

you have poke around in code of application server tomcat or jetty see how interact socket. here's 1 from tomcat.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -