my server look something like this: class DataServer static Data data = null; public static void main (String[] args){ data = new Data("db.db"); DataImpl impl = new DataImpl(data); .. // bind impl to registry.. ... } public static Data getDataReference(){ return data; } } I am trying to get a copy of the data reference so I add the getDataReference method. All the things works well...local...remote...concurrent access..without using that getDataReference() but as I call the getDataReference method...I got a null. Can anyone tell me why ? since there is only one copy of data object...and the server is already (and still) running, the data must have contained something right? but why would I get a null ? Thanks in advance Karl
Rick Fortier
Ranch Hand
Joined: Jun 04, 2001
Posts: 147
posted
0
Try taking static off of the getDataReference() method. I have not tested my theory. But off the top of my head I don't think that static methods have access to the this variable. Let me know if that was it. The only other thing I can think of is that data is really null.
[This message has been edited by Rick Fortier (edited June 16, 2001).]
Karl Fu
Ranch Hand
Joined: Mar 26, 2001
Posts: 41
posted
0
Hi rick, Thanks for your response. I really needed the method to static because this method will be used by some other class. if it is not static ..then i will have to create a server object...which seems alittle weird. With regard to your second comment, you mean a static method have no access to a static variable ? I think static method can only operate on static variables or non-static variable within the static block.. and non-static method can access static variable....isn't it ? I think the data variable cannot be null in this case...because it is being used ( the applicationi is actualy running ). What i have in mind is that the acessing sequence of the 2 static methods on the same staic variable causing this problem. Since the server is running , so the static main method is still running and didnt return. so getDBReference() method didn't get the changed data variable.... but does it make sense ? I really doubt it myself too please give me some comment. Karl
Rajesh Pohuja
Greenhorn
Joined: May 29, 2001
Posts: 6
posted
0
It could be because DataServer doesn't implement Remote, thus is serialized/de-serialized when accessed by the client. Now, the static fields do not participate in serialization process, thus you get a null !! Does it make sense?
Karl Fu
Ranch Hand
Joined: Mar 26, 2001
Posts: 41
posted
0
Rajesh, I was using this method in a local server mode though. Let me explain a little bit more about what i am doing : 3 modes : 1. Local mode (create a new Data object) 2. Local server mode (local access through a running rmi server, do not create any new Data object, obtaining a Data object reference created by the server....this is done by the getDBReference()) 3. Remote mode So, I am actually accessing the doin thing in mode 2, which is local. I think there will not be any serialization involve in this case. I am trying this out hoping that this will keep only one copy of Data object, even if a server is running on the same data object, I will be able to have concurrency control to access the same data object through both local and remote mode.