Created
February 1, 2015 13:26
-
-
Save kineticz/f742dbf086dbb39acb74 to your computer and use it in GitHub Desktop.
Why should we `synchronized(original)` since `original` is already thread safe?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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