Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public synchronized void enter(Object item){
- while (count == BUFFER_SIZE){
- try{
- wait();
- }
- catch (InterruptedException e) {}
- }
- // add an item to the buffer
- ++count;
- buffer[in] = item;
- in = (in+1) % BUFFER_SIZE;
- notify();
- }
- public synchronized void remove(Object item){
- while (count == 0){
- try{
- wait();
- }
- catch (InterruptedException e) {}
- }
- // remove an item to the buffer
- --count;
- item = buffer[out];
- out = (out+1) % BUFFER_SIZE;
- notify();
- return item;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement