You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by "Allan, Brad (Wokingham)" <Br...@Fiserv.com> on 2013/03/19 18:22:44 UTC

RAMDirectory code - locking?

There are a number of

'lock (this)'

statements in the code?



Just wanting to check this has been considered and was considered safe.



I'm used to seeing the use of some sort of Locker object to do this.



Public class Bla {

         private static Object locker = new Object();



         Public void someMethod() {

                 Lock(locker) {

                          //do some stuff!

                 }

         }
}

Brad Allan
Development Lead
Risk & Compliance
Fiserv
Office: +44 (0) 845 013 1137
Mobile: +44 (0) 7866 720024
www.fiserv.com<http://www.fiserv.com/>


________________________________

CheckFree Solutions Limited (trading as Fiserv)
Registered Office: Eversheds House, 70 Great Bridgewater Street, Manchester, M15 ES
Registered in England: No. 2694333

Re: RAMDirectory code - locking?

Posted by Nicholas Paldino <ca...@caspershouse.com>.
Brad et al,

You are correct, it is unsafe in that it exposes the synchronization object that is used (since this is accessible by anything that has a reference to it).

At worst, you're exposing that object to deadlocks (or possible DoS depending on how exposed the reference is).

General best practice says to store it as a private implementation detail (this is a leaky implementation).

If there are synchronization issues involving that and other objects, it's usually indicative of a larger design issue.

- Nick

On Mar 19, 2013, at 5:43 PM, "Allan, Brad (Wokingham)" <Br...@Fiserv.com> wrote:

> to confirm my question is related to how the locking is being done.
> Thanks.
> 
> (Sent from my Blackberry device)
> Brad Allan
> Development Lead
> Risk & Compliance
> Fiserv
> Office: +44 (0) 845 013 1137
> Mobile: +44 (0) 7866 720024
> Fax: +44 (0) 845 013 1010
> www.fiserv.com
> 
> ----- Original Message -----
> From: Rob Cecil [mailto:rob.cecil@gmail.com]
> Sent: Tuesday, March 19, 2013 05:16 PM
> To: user@lucenenet.apache.org <us...@lucenenet.apache.org>
> Subject: Re: RAMDirectory code - locking?
> 
> I think the question is more about Lock(this) rather than
> Lock(mySimpleObject), e.g.:
> 
> http://stackoverflow.com/questions/2319286/what-to-pass-to-the-lock-keyword
> 
> 
> On Tue, Mar 19, 2013 at 4:38 PM, Anders Lybecker <an...@lybecker.com>wrote:
> 
>> Hi Brad,
>> 
>> I'm not really sure what your question is?
>> 
>> Is use of the C# Lock keyword safe in RamDirectory? Yes it is. Is it a
>> performance issue? No, not really. It is common in multi-threaded code
>> 
>> Regards,
>> Anders Lybecker
>> 
>> 
>> On Tue, Mar 19, 2013 at 6:22 PM, Allan, Brad (Wokingham) <
>> Brad.Allan@fiserv.com> wrote:
>> 
>>> There are a number of
>>> 
>>> 'lock (this)'
>>> 
>>> statements in the code?
>>> 
>>> 
>>> 
>>> Just wanting to check this has been considered and was considered safe.
>>> 
>>> 
>>> 
>>> I'm used to seeing the use of some sort of Locker object to do this.
>>> 
>>> 
>>> 
>>> Public class Bla {
>>> 
>>>         private static Object locker = new Object();
>>> 
>>> 
>>> 
>>>         Public void someMethod() {
>>> 
>>>                 Lock(locker) {
>>> 
>>>                          //do some stuff!
>>> 
>>>                 }
>>> 
>>>         }
>>> }
>>> 
>>> Brad Allan
>>> Development Lead
>>> Risk & Compliance
>>> Fiserv
>>> Office: +44 (0) 845 013 1137
>>> Mobile: +44 (0) 7866 720024
>>> www.fiserv.com<http://www.fiserv.com/>
>>> 
>>> 
>>> ________________________________
>>> 
>>> CheckFree Solutions Limited (trading as Fiserv)
>>> Registered Office: Eversheds House, 70 Great Bridgewater Street,
>>> Manchester, M15 ES
>>> Registered in England: No. 2694333
> 
> ________________________________
> 
> CheckFree Solutions Limited (trading as Fiserv)
> Registered Office: Eversheds House, 70 Great Bridgewater Street, Manchester, M15 ES
> Registered in England: No. 2694333
> 

Re: RAMDirectory code - locking?

Posted by "Allan, Brad (Wokingham)" <Br...@Fiserv.com>.
to confirm my question is related to how the locking is being done.
Thanks.

(Sent from my Blackberry device)
Brad Allan
Development Lead
Risk & Compliance
Fiserv
Office: +44 (0) 845 013 1137
Mobile: +44 (0) 7866 720024
Fax: +44 (0) 845 013 1010
www.fiserv.com

----- Original Message -----
From: Rob Cecil [mailto:rob.cecil@gmail.com]
Sent: Tuesday, March 19, 2013 05:16 PM
To: user@lucenenet.apache.org <us...@lucenenet.apache.org>
Subject: Re: RAMDirectory code - locking?

I think the question is more about Lock(this) rather than
Lock(mySimpleObject), e.g.:

http://stackoverflow.com/questions/2319286/what-to-pass-to-the-lock-keyword


On Tue, Mar 19, 2013 at 4:38 PM, Anders Lybecker <an...@lybecker.com>wrote:

> Hi Brad,
>
> I'm not really sure what your question is?
>
> Is use of the C# Lock keyword safe in RamDirectory? Yes it is. Is it a
> performance issue? No, not really. It is common in multi-threaded code
>
> Regards,
> Anders Lybecker
>
>
> On Tue, Mar 19, 2013 at 6:22 PM, Allan, Brad (Wokingham) <
> Brad.Allan@fiserv.com> wrote:
>
> > There are a number of
> >
> > 'lock (this)'
> >
> > statements in the code?
> >
> >
> >
> > Just wanting to check this has been considered and was considered safe.
> >
> >
> >
> > I'm used to seeing the use of some sort of Locker object to do this.
> >
> >
> >
> > Public class Bla {
> >
> >          private static Object locker = new Object();
> >
> >
> >
> >          Public void someMethod() {
> >
> >                  Lock(locker) {
> >
> >                           //do some stuff!
> >
> >                  }
> >
> >          }
> > }
> >
> > Brad Allan
> > Development Lead
> > Risk & Compliance
> > Fiserv
> > Office: +44 (0) 845 013 1137
> > Mobile: +44 (0) 7866 720024
> > www.fiserv.com<http://www.fiserv.com/>
> >
> >
> > ________________________________
> >
> > CheckFree Solutions Limited (trading as Fiserv)
> > Registered Office: Eversheds House, 70 Great Bridgewater Street,
> > Manchester, M15 ES
> > Registered in England: No. 2694333
> >
>

________________________________

CheckFree Solutions Limited (trading as Fiserv)
Registered Office: Eversheds House, 70 Great Bridgewater Street, Manchester, M15 ES
Registered in England: No. 2694333

Re: RAMDirectory code - locking?

Posted by Rob Cecil <ro...@gmail.com>.
I think the question is more about Lock(this) rather than
Lock(mySimpleObject), e.g.:

http://stackoverflow.com/questions/2319286/what-to-pass-to-the-lock-keyword


On Tue, Mar 19, 2013 at 4:38 PM, Anders Lybecker <an...@lybecker.com>wrote:

> Hi Brad,
>
> I'm not really sure what your question is?
>
> Is use of the C# Lock keyword safe in RamDirectory? Yes it is. Is it a
> performance issue? No, not really. It is common in multi-threaded code
>
> Regards,
> Anders Lybecker
>
>
> On Tue, Mar 19, 2013 at 6:22 PM, Allan, Brad (Wokingham) <
> Brad.Allan@fiserv.com> wrote:
>
> > There are a number of
> >
> > 'lock (this)'
> >
> > statements in the code?
> >
> >
> >
> > Just wanting to check this has been considered and was considered safe.
> >
> >
> >
> > I'm used to seeing the use of some sort of Locker object to do this.
> >
> >
> >
> > Public class Bla {
> >
> >          private static Object locker = new Object();
> >
> >
> >
> >          Public void someMethod() {
> >
> >                  Lock(locker) {
> >
> >                           //do some stuff!
> >
> >                  }
> >
> >          }
> > }
> >
> > Brad Allan
> > Development Lead
> > Risk & Compliance
> > Fiserv
> > Office: +44 (0) 845 013 1137
> > Mobile: +44 (0) 7866 720024
> > www.fiserv.com<http://www.fiserv.com/>
> >
> >
> > ________________________________
> >
> > CheckFree Solutions Limited (trading as Fiserv)
> > Registered Office: Eversheds House, 70 Great Bridgewater Street,
> > Manchester, M15 ES
> > Registered in England: No. 2694333
> >
>

Re: RAMDirectory code - locking?

Posted by Anders Lybecker <an...@lybecker.com>.
Hi Brad,

I'm not really sure what your question is?

Is use of the C# Lock keyword safe in RamDirectory? Yes it is. Is it a
performance issue? No, not really. It is common in multi-threaded code

Regards,
Anders Lybecker


On Tue, Mar 19, 2013 at 6:22 PM, Allan, Brad (Wokingham) <
Brad.Allan@fiserv.com> wrote:

> There are a number of
>
> 'lock (this)'
>
> statements in the code?
>
>
>
> Just wanting to check this has been considered and was considered safe.
>
>
>
> I'm used to seeing the use of some sort of Locker object to do this.
>
>
>
> Public class Bla {
>
>          private static Object locker = new Object();
>
>
>
>          Public void someMethod() {
>
>                  Lock(locker) {
>
>                           //do some stuff!
>
>                  }
>
>          }
> }
>
> Brad Allan
> Development Lead
> Risk & Compliance
> Fiserv
> Office: +44 (0) 845 013 1137
> Mobile: +44 (0) 7866 720024
> www.fiserv.com<http://www.fiserv.com/>
>
>
> ________________________________
>
> CheckFree Solutions Limited (trading as Fiserv)
> Registered Office: Eversheds House, 70 Great Bridgewater Street,
> Manchester, M15 ES
> Registered in England: No. 2694333
>