I thought I wrote it right, but I dont follow where the mistake is. I create a singleton class (of ringbuffer using apache commons); this is used in mainactivity and guimanager (both are my implementation)-hence a singleton class for ringbuffer. Above classes get the reference for singleton by calling
RingBuffer.getInstance()
At some point, user wants to change the size of the ring buffer, so I recreate the singleton class by calling
RingBuffer.recreateRingBuffer()
Question: After recreating the instance of singleton class, I was hoping that existing references in mainactivity and guimanager would be modified automatically with the new reference (of ringbuffer with different size). But no, I still have the old reference (the buffere with the old size). In other words, how can I make the return value of getInstance() modified automatically anytime the reference is modified (so the caller methods and the ringbuffer are working on the same copy of the object)
Here is my singleton class
import java.util.Arrays;
import org.apache.commons.collections.buffer.CircularFifoBuffer;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.math3.stat.StatUtils;
import android.util.Log;
public class RingBuffer {
private CircularFifoBuffer buffer;
private int size;
private volatile static /*final*/ RingBuffer instance = new RingBuffer(7);
private RingBuffer(int n) {
size = n;
buffer = new CircularFifoBuffer(size);
}
public static RingBuffer getInstance() {
return instance;
}
public static RingBuffer recreateRingBuffer(int n) {
Log.e(Constants.GLOBALTAG,"Recreating RingBuffer of Size "+n);
instance=null;
instance=new RingBuffer(n);
return instance;
}
}