Title: Prevent programmers from acquiring lock on class instance
Tags: java;concurrency
Question: Is it possible to write a class such that other programmers cannot acquire a lock on an instance of the class?
Lock-abuse, if there's a term like that, can be a serious killer. unfortunately, programmers torn between the disastrous forces of delivering thread-safe code and limited knowledge of concurrency, can wreak havoc by adopting the approach of locking instances even when they're invoking operations which really don't require the instance's resources to be blocked
Comment: other programmers = those who would use the library i develop, and/or, maintainers of the codebase who would need to work with the class i've written

Comment: the question is not quite clear. What do you mean by "other programmers". Is your codebase split into pieces not accessible to some?

Here is the accepted answer: The only way to do this is to ensure that the classes instances are not visible.  For example, you could declare is as a private nested class, and make sure that the enclosing class does not leak reference instances.
Basically, if something can get hold of a reference to an instance, there is nothing to stop it from locking it.
Normally, it is sufficient to ensure that the reference to the lock object doesn't leak ... and not worry about the class visibility.
FOLLOW UP - in response to the OP's comments.
You cannot stop someone else's code from taking a lock an instance of one of your classes.  But you can design your class so that this won't interfere with your classes internal synchronization.  Simply arrange that your class uses a private object (even an Object instance) for synchronizing.
In the more general sense, you cannot stop application programmers from using your classes in ways that you don't like.  Other examples I've heard of (here) include trying force people to override methods or provide particular constructors.  Even declaring your class fields private won't stop a determined (or desperate) programmer from using reflection to phillipterry@example.com.
But the flip-side is that those things you are trying to prevent might actually not be stupid after all.  For example, there could actually be a sound reason for an application to use your class as a lock object, notwithstanding your objection that it reduces concurrency.  (And it in general it does,  It is just that this may not be relevant in the particular case.)
My general feeling is that is a good idea to document the way your class is designed to be used, and design the API to encourage this.  But it is unwise to try to force the issue.  Ultimately it is the responsibility of the people who code against your classes to use them sensibly ... not yours.
Comment for this answer: Synchronizing on a ConcurrectHashMap only impacts code which synchronizes on it. Anyone calling the map normally will be unaffected.
Comment for this answer: while i believe your response to be the most suitable, i guess it just points to the fact that class instances can't be protected as such from locking. the class - ConcurrentHashMap - probably highlights my dilemma. Even though it has a highly sophisticated concurrency handling capability, but someone might just synchronize its instance and undo all the optimisations. In this aspect, i guess naming the class to include 'Concurrent' is also a good strategy :]

Here is another answer: If a class has members that require protection from concurrent access, locking should be done internally.  Otherwise, you're forcing those who use it to understand the details of its implementation when they shouldn't be able to see past its interface.

Here is another answer: When creating a new instance, also create a new thread which immediately synchronizes on the instance and goes to sleep (with Thread.sleep()). Any code trying to synchronize on the instance will just deadlock, thus the developer has to rethink his approach.
Disclaimer:
Don't vote me done because my suggestion is insane. I know it is. I am just answering the question. Do not actually do this!!!

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:09/24/10', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<java><concurrency>', 'Title': 'Prevent programmers from acquiring lock on class instance', 'ViewCount': 196, 'id': 3785963, 'user_AboutMe': '<p>ding!</p>\n', 'user_AccountId': 165652.0, 'user_DisplayName': 'anirvan', 'user_Reputation': 4667.0, 'user_Views': 323.0, 'user_id': 389287.0}}