Java: removing memory to disk

Let's say I have a Java application that does something like this:

  • Initialize (it takes a long time because it is difficult)
  • Do some things fast
  • Wait a long time (your favorite gear is here)
  • Go to step 2.

Is there a way to encourage or force the JVM to flush memory to disk for extended periods of inactivity? (for example, at the end of step 2, make some function calls that effectively say "HEY JVM! I'm going to sleep for a while.")

I do not mind using a large fragment of virtual memory, but physical memory is on the machine that I use, because there are many background processes.

+3
source share
6 answers

The operating system should handle this, I think.

Otherwise, you could manually save your application to post-initialize the disk or database and perform faster initialization of this data, maybe?

+2
source

Instead of having your program sit idle and use resources, why not schedule it with cron? Or even better, since you are using Java, are you planning it with Quartz ? Do your best to cache elements of your lengthy initialization process, so you don't have to pay heavy fines every time a scheduled task starts.

+2
source

, , , . .

-, , JVM, .

. , 100 java, 100 . 10 , VM - 100 . , VM .

"" , , ​​.

VM, :

-XX: MaxHeapFreeRatio = 70 GC, .

-XX: MinHeapFreeRatio = 40 GC, .

VM , 70%. , , , .

. :

GC GC HotSpot: Java HotSpot. : http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf

, , . , .

+2

, , , Win32, - DLL, SetProcessWorkingSetSize JNI. , WS. -1, .

+1

, - , , ?

  • : " ".
  • , .
  • Worker , .
  • , , , , Worker null.
  • .
  • , Worker .
  • , , , Worker null.
  • .

, Worker ( gc , gc , System.gc() Worker null), , , . "x" , java.util.Timer Server .

EDIT: JVM -Xmx, JVM. , , , .

0

? JVM - . , , , .

, , ... - ( ..) , , . JVM , , , ( GC / ).

If you make sure that all of the memory allocated in each individual phase of the program’s life is GCable before the start of the next phase, you can use the -Xmx option to reduce the maximum process size and result in a permanent program. GC between phases. I have done this before with some success.

0
source

Source: https://habr.com/ru/post/1720480/


All Articles