Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collection;
- public class TestBuffer{
- private Collection<Object> list = new ArrayList<Object>();
- private boolean insideGetBuffer = false;
- public TestBuffer(){
- System.out.println("Creating a TestBuffer");
- }
- synchronized public void add(Object item) {
- list.add(item);
- }
- synchronized public void remove(Object item) {
- if(insideGetBuffer){
- System.out.println("Broke Synchronization ");
- System.out.println(item);
- }
- }
- synchronized public void getBuffer() {
- insideGetBuffer = true;
- try{
- int i=0;
- for(Object item : list) {
- if(item != null){
- i++;
- }
- }
- }finally{
- insideGetBuffer = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement