public static CircularBuffer buf = new CircularBuffer(100);
}
package app;
public class Get implements Runnable {
public void run() { while (true) { try { Thread.sleep(1000); BufferPool.buf.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
}
package app;
public class Put implements Runnable {
public void run() { while (true) { int num = (int) (Math.random() * 1000); int degree = (int) (Math.random() * 1000); SensorRecord rec = new SensorRecord(num, degree); try { Thread.sleep(10); BufferPool.buf.put(rec); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
}
package app;
public class SensorRecord {
public SensorRecord(int num2, int degree2) { // TODO Auto-generated constructor stub this.num = num2; this.degree = degree2; }
int num; int degree;
public String toString(){ return new String("num: " + num + "; degree: " + degree); }
}
package app;
public class TestBuffer {
/** * @param args */
public static void main(String[] args) { Get get = new Get(); Put put = new Put(); Thread thread = new Thread(get); Thread thread2 = new Thread(put); thread.start(); thread2.start();
} } package app;
public class BufferPool {
public static CircularBuffer buf = new CircularBuffer(100);
}
package app;
public class Get implements Runnable {
public void run() { while (true) { try { Thread.sleep(1000); BufferPool.buf.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
}
package app;
public class Put implements Runnable {
public void run() { while (true) { int num = (int) (Math.random() * 1000); int degree = (int) (Math.random() * 1000); SensorRecord rec = new SensorRecord(num, degree); try { Thread.sleep(10); BufferPool.buf.put(rec); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
}
package app;
public class SensorRecord {
public SensorRecord(int num2, int degree2) { // TODO Auto-generated constructor stub this.num = num2; this.degree = degree2; }
int num; int degree;
public String toString(){ return new String("num: " + num + "; degree: " + degree); }
}
package app;
public class TestBuffer {
/** * @param args */
public static void main(String[] args) { Get get = new Get(); Put put = new Put(); Thread thread = new Thread(get); Thread thread2 = new Thread(put); thread.start(); thread2.start();