0

I have an RMI server client relationship (each running in a different JVM), and the RMI server creates a large object and returns it to the RMI client. After this is done which JVM (server or client) owns the actual memory for that object? If the object is passed between JVMs how is that done? Does it involve a disk hit, or is there some magic that makes it super fast?

Thanks

Jon
  • 3,985
  • 7
  • 48
  • 80

1 Answers1

2

It depends on whether this large object is a remote object -- whether it indirectly implements java.rmi.Remote and is exported -- or if it's an ordinary serializable object, in which case it is copied from one JVM to the other. If it's the former, then it always stays in the JVM that created it. If it's the later, then it's copied from one to the other when it's passed as an argument to a remote method, or returned from a call to a remote method. The copies are plain, ordinary Java objects, and subject to being garbage collected at either end according to normal rules.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
  • The object would be a BufferedImage, which is not serializable. Does this imply that a BufferedImage cannot be returned from an RMI method? – Jon Apr 07 '11 at 00:49
  • So in order to get a BufferedImage back from an RMI server call I'd have to write it to disk myself? What would happen if I tried to return it? – Jon Apr 07 '11 at 01:17
  • You would get a NotSerializableException at runtime. I would look at ways to return the essential part of the BufferedImage -- i.e., a portable pixel representation like RGB values -- as an array, which would be serializable. Either that, or provide a "BufferedImageServer", which wrapped whatever BufferedImage APIs you needed, so you could call them remotely. – Ernest Friedman-Hill Apr 07 '11 at 01:22