Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public interface Snapshot<T> {
  2.   public void update(T v);
  3.   public T[] scan();
  4. }
  5.  
  6. public class SeqSnapshot<T> implements Snapshot<T> {
  7.   T[] a_value;
  8.   public SeqSnapshot(int capacity, T init) {
  9.     a_value = (T[]) new Object[capacity];
  10.     for (int i = 0; i < a_value.length; i++) {
  11.       a_value[i] = init;
  12.     }
  13.   }
  14.   public synchronized void update(T v) {
  15.     a_value[ThreadID.get()] = v;
  16.   }
  17.   public synchronized T[] scan() {
  18.     T[] result = (T[]) new Object[a_value.length];
  19.     for (int i = 0; i < a_value.length; i++)
  20.     result[i] = a_value[i];
  21.     return result;
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement