Skip to content

Instantly share code, notes, and snippets.

@kineticz
Created February 1, 2015 13:26
Show Gist options
  • Select an option

  • Save kineticz/f742dbf086dbb39acb74 to your computer and use it in GitHub Desktop.

Select an option

Save kineticz/f742dbf086dbb39acb74 to your computer and use it in GitHub Desktop.
Why should we `synchronized(original)` since `original` is already thread safe?
package je3.thread;
/**
* Created by IDEA on 01/02/15.
*/
public class ThreadSafeIntList {
protected int[] data;
protected int size = 0;
private static final int default_capacity = 8;
public ThreadSafeIntList() {
data = new int[default_capacity];
}
public ThreadSafeIntList(ThreadSafeIntList original) {
synchronized (original) {
this.data = (int[]) original.data.clone();
this.size = original.size;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment