Re: Efficiency about hashtable, arraylist, string and synchronization



Hashtable, but not your way ;-p

The string option is bad. Don't go near it. Firstly you would need a
delimiter, but mainly because strings are immutable (and hence your code is
actually wrong). You would need sList = sList.Replace(id,""); but now you
have multiple lock objects; OK you could avoid this with a separate lock,
but you are still making *lots* of strings.

Personally I also wouldn't go near the .Synchronized options... I'd just:

lock(hList) {
hList.Add(id);
}

etc; this way you know the duration of the lock, so you can safely do
multiple steps as an atomic unit:
lock(hList) {
if(!hList.Contains(id)) {
hList.Add(id,id); // value is dummy
}
}

Note also that (assuming ID is an integer) this will involve boxing; if you
can, I would suggest moving to 2.0 and using a Dictionary<int,int>.

Marc


.



Relevant Pages

  • Re: synchronized using String.intern()
    ... would obviously not lock the file from access by another process, ... In my case, the number of such strings is guaranteed to be on the order of 1-10, so, again, I don't care. ... ADD ENTRY TO FILE GIVING FILE ... public void doSomeOtherLowLevelOperationOfYourApplication() { ...
    (comp.lang.java.programmer)
  • Re: synchronized statements
    ... > A quick solution not involving the synchronized keyword is to print only one ... This doesn't stop the printing of one set of strings interrupting the ... I'm surprised acquiring the lock on System.out didn't work. ...
    (comp.lang.java)
  • Floyd Roses saddle blocks: silly?
    ... Floyd Rose's saddle blocks are used to lock the strings in place. ... Isn't that a major design flaw? ... add complexity to the bridge design and end up making the manufacturing process more expensive, ...
    (alt.guitar)
  • Re: Charvel Model I Tuning
    ... Make sure the strings are wound on the tuners so they essentially lock in ... You will need to stretch the strings out really good before you lock ... Tune the guitar roughly to tune, ... either you're winding them wrong or you have a problem with the tuners. ...
    (alt.guitar)