public class ResourceGuard extends Object implements AutoCloseable, Serializable
acquireResource()
call. As a result
of the call, each client gets a ResourceGuard.Lease
. The close()
method of the lease releases
the resources and reduces the client count in the ResourceGuard
object. The protected
resource should only be disposed once the corresponding resource guard is successfully closed,
but the guard can only be closed once all clients that acquired a lease for the guarded resource
have released it. Before this is happened, the call to close()
will block until the
zero-open-leases condition is triggered. After the resource guard is closed, calls to acquireResource()
will fail with exception. Notice that, obviously clients are responsible to
release the resource after usage. All clients are considered equal, i.e. there is only a global
count maintained how many times the resource was acquired but not by whom.限定符和类型 | 类和说明 |
---|---|
class |
ResourceGuard.Lease
A lease is issued by the
ResourceGuard as result of calls to acquireResource() . |
构造器和说明 |
---|
ResourceGuard() |
限定符和类型 | 方法和说明 |
---|---|
ResourceGuard.Lease |
acquireResource()
Acquired access from one new client for the guarded resource.
|
void |
close()
Closed the resource guard.
|
void |
closeInterruptibly() |
void |
closeUninterruptibly()
If the current thread is interrupted while waiting for the
close method to complete, then it will continue to wait.
|
int |
getLeaseCount()
Returns the current count of open leases.
|
boolean |
isClosed()
Returns true if the resource guard is closed, i.e. after
close() was called. |
public ResourceGuard.Lease acquireResource() throws IOException
IOException
- when the resource guard is already closed.public void closeInterruptibly() throws InterruptedException
public void closeUninterruptibly()
public void close()
acquireResource()
have seen their matching call to releaseResource()
.close
在接口中 AutoCloseable
public boolean isClosed()
close()
was called.public int getLeaseCount()
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.