Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM copies an object when it is exported to RMI registry?

 
Rafael Z. Frantz
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I've noticed that when an object is exported to the RMI registry the JVM makes a copy of it. Is it true?

Is there any way to export an object without making this copy?

Thanks,

Rafael.
 
Rafael Z. Frantz
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maneesh,

Thanks for your message, but I am afraid the problem is different. Let me explain it better with this code:






1) The monitor is exported to the RMI registry
2) Proxy is an object created at AnotherClass and when AnotherClass invokes wait() the proxy holds the lock.
3) Proxy is not exported to the RMI registry
4) When Monitor constructor is executed the output is:

PROXY 1 tdg.guarana.toolkit.port.communicator.adapter.jbi.responder.Proxy@1862525
PROXY 2 tdg.guarana.toolkit.port.communicator.adapter.jbi.responder.Proxy@1862525

PROXY 3 tdg.guarana.toolkit.port.communicator.adapter.jbi.responder.Proxy@8720392 <<<<<<<<<<<<<<<< The problem!

As you can see latter when update() is called the object seems to be another one. I am wondering this is due to the object proxy was copied to the RMI registry.

What's your opinion about it?

Regards,

Rafael.

 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code does not compile and i don't think you have given us the entire code. I don't see anyone calling the update() method.
Are these two classes executed in different JVMs?
 
Rafael Z. Frantz
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

These 3 classes are running in a JVM1 and the update() method is invoked by another object that runs in a JVM2. All them in both JVMs are exported to RMI registry, one registry in JVM1 and another at JVM2. The code is not complete since it is long and complex. I´ve tried to put something that focus on the problem.

In JVM1 then proxy calls wait() and own the lock, the problem is that at the time it is exported to the registry at JVM1 the stub at the registry that receives the notification from JVM2 that invokes update(). In this case, the update at the stub cannot call NotifyAll() since it does not own the lock. So no effect in the code...

Regards,

Rafael.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic