Forums Register Login

trouble having ultiple LockManager instances

+Pie Number of slices to send: Send
Hi,
I declare and initialize a Singleton LockManager
instance in DataInterface, RemoteDataAccess and LocalDataAcccess implement DataInterface. Since
I use Singleton to control LockManager instance
creation, and variables in an interface should be public, static, and final. So, I suppose there should be one LockManager instance shared by all remote accesses. Somehow, in the client, every time I get a remote connection (which is DataInterface since RemoteDataAccess sits in server, and that for hiding the distinction of local/remote connections), a new LockManager is created. In lock/unclock methods of RemoteDataAccess, I only use the LockManager instance created in DataInterface. I am confused about this. I believe something is wrong with my design. Any suggestions appreciated.
+Pie Number of slices to send: Send
Holmes,
I don't know the reason behind keeping an instance of the LockManager in the DataInterface. All you have to do is whenever you need a LockManager instance from the RemoteDataAccess, you make a call like:
LockManager.getInstance();
+Pie Number of slices to send: Send
Thanks, Sai:
I did exactly like what you mentioned. Somehow,
I did some checking inside getInstance() function:
every time a client window starts up, (private static) LockManager variable got initialized. I am wondering if a Singleton instance only applied to a single VM, not for multiple VM's. Or somethig
else plays a role in this thing. Here is my code:
In LockManager class:

And in RemoteDataAccess class, I used LockManager.getInstance() to access lock and unlock methods. Everytime a remote connection is
established, "Create new manager" will appear.
Right now I am using multiple Data instances for
multiple remote connections, but I don't think this has anything to do with it.
[ June 19, 2002: Message edited by: Holmes Wong ]
+Pie Number of slices to send: Send
Could anyone tell what is wrong with my implementation or give an pointer? Thanks.
+Pie Number of slices to send: Send
 


Somehow, in the client, every time I get a remote connection (which is DataInterface since RemoteDataAccess sits in server, and that for hiding the distinction of local/remote connections), a new LockManager is created.


Sounds like your singleton is a singleton for a given connection only. If you want a single object to be shared by all connections, you need to create it on the server and pass a reference to it to all the connections.
In my implementation, I actually instantiate LockManager from the Data constructor.
Eugene.
+Pie Number of slices to send: Send
Holmes,
The value of instance is obviously null when you call getInstance() every time from the Connection object. Check for places where you might set the instance variable to null.
+Pie Number of slices to send: Send
Guys, thank you for giving pointers. I will try out these ideas.
+Pie Number of slices to send: Send
Holmes:
getInstance method should be synchronized.
If Lockmanager.getInstance is called in 3
different threads simultaneously there is
chance that all 3 see instance initialized to
null and all 3 can create new objects.
This is called "Lazy initialization" problem.
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 858 times.
Similar Threads
Connection Object for lock/unlock...?
Lock Manager
Implementing Lock/Unlock
posting again...pl help
dumb qn: Classes stored in Remote client
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:55:49.