Is there any cache in jvm or a way how to speed up method which sometimes takes longer?

Hi is there any cache or settings of the jvm to speed up methods call?

e.g: I do have a web service and when I call it once per 10minutes or so it's quite slow processing takes around 8-10s in comparison to calling it once per 20seconds-the result is roughly around 5s.

Nothing else except this is running on the server. Is there a way to speed it up? (I cannot cache any objects or so.)

I used JProfiler, I call it with the same parameters. It's doing exatly the same thing. The difference is between times when I call it. How long the server is idle. 1 or 30minutes is difference.


EDIT: platform is: AIX java: IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc64-64 .. server: tomcat


Factors which could explain such behavior:

  • Swapping - Low activity OS processed gets swapped out
  • Priority - OS process priority can a bit mysterious sometimes, especially if a process is mostly idle.
  • JIT - The more you call a method, the more it gets optmized
  • GC - Garbage collector take some time to stabilize, which can result in different behaviour under different loads. The -server option is basically a preset configuration for the JVM.
  • Pooling - Threads and other resources gets pooled. Under low activity pool may shrink and object will need to be re-allocated

Investigating such kind of issue can be hard. I would suggest you try to correlated OS-level information with JVM-level information. A profiler is maybe not the best tool, try with JConsole, mem, etc.

Try also to identify the deviation between different typical scenario, e.g. first request after startup, request under heavily load, request under medium load, etc. Try to identify when the response time change.


Use a Profiler.

JProfiler would be a good choice.

Using a profiler you can identity hotspots in your code. Once you have indentified those hotspots you can think about various way to improve those hot spots in terms of space and time.


Apart from improving the code itself, make sure the JVM that runs the server is the server vm and not the client vm. Use the -server parameter.

client vm:

Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)

server vm:

Java HotSpot(TM) Server VM (build 14.0-b16, mixed mode)

To find out what you run on production you can programmatically do:


which should give you something like: Java HotSpot(TM) 64-Bit Server VM

Otherwise (if you don't want to touch the code) you can do a thread dump and have a look at the top for something like: Full thread dump Java HotSpot(TM) Server VM (16.0-b13 mixed mode)


Slowness after an idle period is usually caused by the process being swapped out to disk. Modern systems are never idle, and systems like Windows aggressively swap background processes out (non-focus os enough) which frequently happened to Eclipse users.

Please edit your question with information about your platform.


How much load is the server under? After 10 minutes a heavily loaded server has probably swapped out your service to disk or (depending on the server software) shut down the instance of your service that served the last request. This means spooling up the service for your new request is really slow.

A couple of ways you could solve this:

  • Move the service to a server that isn't as heavily loaded
  • Investigate better or more appropriate software to run your service - you haven't mentioned what you are using (eg Tomcat? JBoss?).

I am building a java application and i have implemented custom listeners and events. The problem now is that there are many events and listeners and the application GUI thread is being blocked while ...

I've just learned java but from my old experience coming from C++ i tought that i can write a commandline calculator wich supports all 4 basic operators with just one line. But i am having a bit of ...

I am developing a small application in Java. I am using Java2D Library for drawing some graphical objects. Now i want to draw some semi-circle like shape or in simple words i need to draw this ( shape ...

I can't figure out why the output is different. The output is same only in the range -128 to 127. public class Check { public static void main(String[ ] args) { Integer i1=122; ...