• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where are loaded classes cached

 
Ondrej Homola
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have this small problem with class loading:

When I run a java program, with classpath to a remote jar on a really slow network, it takes a while to load the classes (that is okay).

But if I run the same program again just seconds after, the classes will be loaded immediately. Does that mean, the classes are cached on a disk in the java's cache directory?
Strangely it only works, if I re-run the application until 20 seconds or so. Which also makes it difficult to search for the cached classes on the disk to prove my thought.

I did some network data profiling though. Only the first (slow) run actually downloads the classes from the remote disk.

If there really is some class caching, could anyone point me to some documentation on it?


Thanks a lot.

 
Henry Wong
author
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It's highly unlikely that this has anything to do with the JVM caching classes, and more likely... it's related to the OS doing file caching.

Many network file systems, NFS, SMB, etc., support some type of change detection and file caching.

Henry
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Ondrej Homola
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply, okay I would happily accept that as an explanation, but ...

A program like this ... :


... causes the file to be loaded via the network evey time, so the caching doesn't take place. Shouldn't the OS cache both the File and the .jar in the same way?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/AvailableDoesntDoWhatYouThinkItDoes
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ondrej Homola wrote:... causes the file to be loaded via the network evey time, so the caching doesn't take place. Shouldn't the OS cache both the File and the .jar in the same way?

I guess that files on the network will not be cached in memory by the operating system, because (unlike files on the local harddisk) the operating system does not have full control over them - some other computer may change the file anytime.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic