Alock is a tool for controlling access to a shared resource by multiple threads. Commonly, a lock provides exclusive access to a shared resource: only one thread at a time can acquire the lock and all access to the shared resource requires that the lock be acquired first. However, some locks may allow concurrent access to a shared resource, such as the read lock of a ReadWriteLock.
The use of synchronized methods or statements provides access to the implicit monitor lock associated with every object, but forces all lock acquisition and release to occur in a block-structured way: when multiple locks are acquired they must be released in the opposite order, and all locks must be released in the same lexical scope in which they were acquired.
While the scoping mechanism for synchronized methods and statements makes it much easier to program with monitor locks, and helps avoid many common programming errors involving locks, there are occasions where you need to work with locks in a more flexible way. For example, some algorithms for traversing concurrently accessed data structures require the use of "hand-over-hand" or "chain locking": you acquire the lock of node A, then node B, then release A and acquire C, then release B and acquire D and so on. Implementations of the Lock interface enable the use of such techniques by allowing a lock to be acquired and released in different scopes, and allowing multiple locks to be acquired and released in any order.
With this increased flexibility comes additional responsibility. The absence of block-structured locking removes the automatic release of locks that occurs with synchronized methods and statements. In most cases, the following idiom should be used: Lock l = ...; l.lock(); try // access the resource protected by this lock finally l.unlock(); When locking and unlocking occur in different scopes, care must be taken to ensure that all code that is executed while the lock is held is protected by try-finally or try-catch to ensure that the lock is released when necessary.
Lock implementations provide additional functionality over the use of synchronized methods and statements by providing a non-blocking attempt to acquire a lock (tryLock()), an attempt to acquire the lock that can be interrupted (lockInterruptibly(), and an attempt to acquire the lock that can timeout (tryLock(long, TimeUnit)).
A Lock class can also provide behavior and semantics that is quite different from that of the implicit monitor lock, such as guaranteed ordering, non-reentrant usage, or deadlock detection. If an implementation provides such specialized semantics then the implementation must document those semantics.
Note that Lock instances are just normal objects and can themselves be used as the target in a synchronized statement. Acquiring the monitor lock of a Lock instance has no specified relationship with invoking any of the lock() methods of that instance. It is recommended that to avoid confusion you never use Lock instances in this way, except within their own implementation.
The three forms of lock acquisition (interruptible, non-interruptible, and timed) may differ in their performance characteristics, ordering guarantees, or other implementation qualities. Further, the ability to interrupt the ongoing acquisition of a lock may not be available in a given Lock class. Consequently, an implementation is not required to define exactly the same guarantees or semantics for all three forms of lock acquisition, nor is it required to support interruption of an ongoing lock acquisition. An implementation is required to clearly document the semantics and guarantees provided by each of the locking methods. It must also obey the interruption semantics as defined in this interface, to the extent that interruption of lock acquisition is supported: which is either totally, or only on method entry.
As interruption generally implies cancellation, and checks for interruption are often infrequent, an implementation can favor responding to an interrupt over normal method return. This is true even if it can be shown that the interrupt occurred after another action may have unblocked the thread. An implementation should document this behavior.
A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.
If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens: The lock is acquired by the current thread; or Some other thread interrupts the current thread, and interruption of lock acquisition is supported.
If the current thread: has its interrupted status set on entry to this method; or is interrupted while acquiring the lock, and interruption of lock acquisition is supported, then InterruptedException is thrown and the current thread's interrupted status is cleared.
The ability to interrupt a lock acquisition in some implementations may not be possible, and if possible may be an expensive operation. The programmer should be aware that this may be the case. An implementation should document when this is the case.
If the lock is available this method returns immediately with the value true. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens: The lock is acquired by the current thread; or Some other thread interrupts the current thread, and interruption of lock acquisition is supported; or The specified waiting time elapses
A Lock implementation will usually impose restrictions on which thread can release a lock (typically only the holder of the lock can release it) and may throw an (unchecked) exception if the restriction is violated. Any restrictions and the exception type must be documented by that Lock implementation.
Before waiting on the condition the lock must be held by the current thread. A call to Condition.await() will atomically release the lock before waiting and re-acquire the lock before the wait returns.
I definitely like the idea of being able to lock an item outside of any permissions set so will happily note this request to review internally We also encourage you to share this feature request with your peers/colleagues so that we can grow the votes and get this on the priority list at some point
This would be super useful. Locking for read only would be a GREAT function. Preventing edits on items that must be stored as archive or similar for historic usage only and no more edit or edit only by 1 persona and not many
In terms of feature requests within the community, every quarter we take the features with the top votes to our development team for a response. You can learn more about the process here, All you need to know about our feature request process!
One thing you can do is when its marked complete, is move it or duplicate and move it to another board to which nobody except a select few have permissions. Not ideal but it will create a record that is not easily edited at least.
In my particular case, I had put defaults in my Navigation and Summary headers so that Sorting the columns would still keep the Navigation section in place. (I had formatted the defaults to be unseen by making the font and background the same as the Navigation header).
Having the ability to lock the content at the cell level would be a great thing to add. There have been times when a team member accidentally edited a cell that I had entered a formula into and I had to re-enter the formula. Being able to lock down a particular cell would prevent this.
Agree - this would be a very useful feature. In my case, I need people to be able to edit the Status column, but only for grandchild rows. I need parent and child rows to be locked because they are based on formulas. I can't just lock the parent/child rows themselves because I need users to be able to assign parent/child rows to themselves or other users.
I agree, this would be a useful feature which would allow me to error-proof a process. Currently I have a published sheet in which many of the rows and columns are locked, but a few need to remain unlocked as it requires the user to manually input data into cells within them. However, there are other cells within that same row/column that they should not be editing/deleting formulas from, but are currently able to and often do in error. If I were able to lock those single cells within the sheet, this would prevent them from deleting the formulas.
Similar to the comments above, we have a project sheet where there are certain deadlines that can not be changed by the project manager, and need to go through a specific process before they can be changed. Others can be adjusted as needed by the project manager. We need to be able to lock the specific deadlines without locking the others. Locking the rows will not work because the Project Managers need to be able to update other information for the task such as status. Being able to lock those specific cells would be a huge step in protecting the sheet from inadvertent mistakes being made.
3a8082e126