Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. class PacketBuffer {
  2.     private Lock lock = new ReentrantLock();
  3.     private Condition notFull = lock.newCondition();
  4.     private Condition notEmpty = lock.newCondition();
  5.     Queue<String> packets = new LinkedList<String>();
  6.     public void insert(String guid) throws InterruptedException {
  7.         //FIXME
  8.         lock.lock();
  9.         try {
  10.             while(packets.size() == Define.bufferSize) {
  11.                 System.out.println("Warteschlange voll, kann "+guid+" nicht annehmen.");
  12.                 //FIXME
  13.                 packets
  14.                 if (++?? == ???) ??? = 0;
  15.                 ++count;
  16.                 notFull.await();
  17.             }
  18.             packets.add(guid);
  19.             System.out.println(guid+" ist jetzt in der Warteschlange.");
  20.            
  21.             //FIXME
  22.             notEmpty.signal();
  23.         } finally {
  24.              //FIXME
  25.             lock.unlock();
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement