Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

private static variable in Remote Object  RSS feed

 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I've defined a private static variable in an Object.
When accessed remotely via a RMI Remote interface the variable is null, so I get a NullPointerException when invoking private methods in the Remote Object on it. I had defined the variable as static so that it won't get Serialized as it's quite a large Object.
When accessed locally there are no problems. Can anyone please help ?
Sorry about the brevity of the problem description , but I know so little about this area.
Thanks in advance
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It you don't want it serialized, then declare it transient.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
That was pretty fundamental
i.e static denotes "class state" and not "object state" whereas transient allows one to declare instance data which is not Serialised.
Incidentally, static variables do not get serialized.
I'll try transient and see what happens !!!
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome. Interesting that static variables don't get serialized: I wasn't aware of that. let me know how it goes.
M
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, changing the variable to transient didn't help.
Now I can't even invoke methods on the Remote Object itself remotely, let alone the methods on the private instance transient variable defined in the Object accessed remotely.
Though local access worked a treat.
It's back to the drawing board. I suspect there's some fundamental flaw in my Remote design.
Any more tips will be greatly appreciated.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this link on this site
http://www.javaranch.com/maha/Resources/gotchas_1_.html#SERIALISATION
- the section Reconstituted Serialized Objects
I suspect I may have to serialize the private instance variable as well and redesign the solution so that it isn't a very large object anymore. As I need to invoke the methods on it remotely.
The tricky bit is - the private instance variable is a RandomAccessFile Object .How does one serialize a RandomAccessFile Object ? You guessed it , it's for my Java Developer Assignment..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!