concurrency - Can you lock on a local object in Java? -


I have a snippet of this code

  personal templates recovery (string name) {TemplatesWrapper T = XlCache.get (name); Synchronize (t) {if (! T.isValid ()) {xlCache.remove (name); Return tap; }} Return t.getTemplate (); }  

xlCache is a concurrent hashpe ; My reason for syncing on t is that 2 threads can be televised where Thread 1 is verified that Verdet Thread 2 has already removed the object from the map and then A NullPointerException be thrown is my belief correct because I know that concurrency is one of the more difficult things to think about it and then for my basic question , Can i t Can lock me, even if it's local?

And this is also the private method that makes a call from the public method, does it make a difference?

Edit: My basic premise is that NullPointerException has been thrown because remove () returns boolean < / Code> Synchronization was making profits; However, my question was locking on the local object. Answer

Concurrent HShap (and Maps < / Code> / concurrent map in general terms) if the specified key is not present

But yes, anything

was actually deleted To indicate whether or not it returns remove method boolean . You can lock on local variables after all, you are actually locking through an context (and the monitor connected to the referenced object), not a variable - and in other contemporary modes There will be a single reference.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -