synchronized

How does a synchronized statement work in this case?

Assume I have a class like this: public class Server { public static void main(String[] args) { Map<Integer, ServerThread> registry = Collections.synchronizedMap(new LinkedHashMap<Integer, ServerThread>()); ... while(true) { Socket socket = serverSocket.accept(); ServerThread serverThread = new...

Java: How to do double-checked-locking with an array element?

This is what my code currently looks like: private boolean[] isInitialized = new boolean[COUNT]; private void ensureInitialized(int i) { if (! isInitialized[i]) { initialize(i); isInitialized[i] = true; } } Now I want to have it thread-safe. I know that double-checked-locking in Java is "teh 3vilness!!1", but ...

Sync'd Hashtable not PowerShell display-friendly. Try: [HashTable]::Synchronized(@{})

I have an object coming from .Net that has a property of type SyncHashTable that can't be viewed w/o an exception being thrown. One-line repro: [HashTable]::Synchronized(@{}) Multi-line easier to play with repro: $ht = new-object hashtable $ht.add("foo", "bar") $hts = [Hashtable]::Synchronized($ht) $hts The error: format-default ...