title: How to keep Java Swing application out of swap/page file?
body: <p>So I have this Java Swing app that has a curious usage pattern: it's not used all the time, but when it's used, it's essential that it's available immediately. And when I say immediately, I mean that it has to be ready for user input as soon as user presses shortcut to bring it in foreground.</p>
  
  <p>The problem is, Windows (and OS generally) tends to put applications which are idle in swap. And when application window comes into foreground, on a typical IDE-powered system, it takes a few seconds for JVM to get loaded to memory again, for Swing to redraw window etc. I'm trying to avoid this and somehow suggest to OS to keep application in memory.</p>
  
  <p>I have tried the following:</p>
  
  <ol>
  <li>Playing with -Xms JVM option. This doesn't really help with swap, although it does help somewhat, but it's hard to measure and inconsistent (in other words, fails in most cases).</li>
  <li>Running a task within the app that does something at regular intervals (go through the data, redraw main JPanel, etc). This doesn't seem to help at all. But maybe I haven't thought of correct something.</li>
  <li>Turning off swap file completely. This does help, but is obviously not something that is recommended for all setups, and I can't really bother (or count on) users to do this.</li>
  </ol>
  
  <p>I'd be grateful for any ideas. Application is multiplatform, but focus is on Windows, and I'm OK with doing different thing for different OS if needed. I'm willing to play nice with OS if at all possible but I'm also ready to play rough if needed. My thinking is that OS probably doesn't provide a way for application to communicate its preference, but there must be a way to modify application behavior so that OS figures out that application is not a good candidate to put in swap.</p>
  
  <p>EDIT: I have had some progress on this issue, with option 2. I've created a TimerTask which fires off once an hour and basically brings JFrame to front, that is, executes jFrame.setVisible(true) and jFrame.toFront(). This indeed keeps main window responsive! However as soon as another part of application needs to be accessed there is that dreadful pause again. This makes sense as OS probably keeps in memory only pages that are accessed. There must be a way to access all pages in JVM without flashing application window in front of the user, without needing to know application specific objects (don't want to update this code every time application is modified), and without compiler deciding that the access operation is no-op and skipping it.</p>