What are leases?

Tim Rohaly

Leases in Jini are used by services to control resource allocation and usage. In general, a service provides a client with use of some resource, whether it is memory, processor time, or even specialized hardware on the server machine. In an application running under one JVM, resources are managed through garbage collection; unused objects are automatically reclaimed, along with their resources. In a distributed environment like Jini, the service needs a different way to keep track of clients that fail, clients that become unreachable due to network failure, and clients that cease to need the service's allocated resource.

Both Jini and RMI use the concept of leasing for this purpose. Leases are granted by services and are used to loan use of that service to a client. A client can request use of the resource from the service; the service determines whether to grant the lease and for how long to lease the resource. A client that acquires a lease obtains the right to use the resource for the entire timespan of the lease. The client can either let the lease lapse or request to renew the lease before it expires.

A service must make the leased resource available for the entire time the lease is in effect, but is free to deallocate the resource when the lease expires. Thus, if the network fails or the client crashes, the service will be able to eventually reclaim its resources.

Exclusive leases allow only one client to use the resource during the lease period, and non-exclusive leases allow any number of clients. A service is free to impose limitations on the number of clients, the amount of time it grants each client, or even which clients it accepts.