Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need some clarification on locking

 
joel smither
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm working the urlybird developer project and I have a question about locking.

The instructions given to me state that I can assume that at any moment, only one program is accessing the database file, therefore the locking system only needs to be concerned with multiple concurrent clients of my server.

Question 1) I'm not sure what the above statement really means. If I have multiple clients connected to a single server, each of the clients has a database connection to the same database file, so how can only one program be accessing the database file?

Question 2) doesn't RMI handle the threading of the client connections? In other words, when a client desires a connection to the server thru RMI, doesn't RMI create a separate thread for that connection?
 
Dieskun Koper
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I means that there is only one server using that database file.
If several servers could be running at the same time using the same database file, you'd also have to consider file locking. This comment says that you do not have to take that into account.
 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
--------------------------------------------------------------------------
Question 2) doesn't RMI handle the threading of the client connections? In other words, when a client desires a connection to the server thru RMI, doesn't RMI create a separate thread for that connection?
----------------------------------------------------------------
yes, RMI is just work like that. It is a kind of server.
 
joel smither
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still not sure I really understand. Suppose my server does a
rebind like this: Naming.rebind(serverObjName, dbServer)

dbServer is the service that each of the clients will refer to when they
want to access the database remotely. Does RMI create a seperate thread for
client connection 1, then another thread for client connection 2, etc?

As a result, I'll have multiple threads accessing the SAME dbServer object?
Is that true?
 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-------------------------------------
Does RMI create a seperate thread for
client connection 1, then another thread for client connection 2, etc?

As a result, I'll have multiple threads accessing the SAME dbServer object?
-------------------------------------
sure, so you get it.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joel,

Did question 1 get answered to your satisfaction?

Question 2) doesn't RMI handle the threading of the client connections? In other words, when a client desires a connection to the server thru RMI, doesn't RMI create a separate thread for that connection?


Just being pendantic here - there is no guarantee that you will get a separate thread for each connection (in fact the RMI specification explicitly states that there are no guarantees regarding thread usage).

The current Sun implementation of RMI appears to maintain a pool of threads which may be used and/or reused. So the following is possible:
  • Client A calls remote lock method which runs in thread 1
  • Client B calls remote lock method which runs in thread 2
  • Client C calls remote lock method which runs in thread 1
  • Client A calls remote read which runs in thread 3
  • Client B calls remote read which runs in thread 1

  • And this is just one possibility - there are many other permutations.

    Regards, Andrew
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic