safriansah

Sinkronisasi dalam Java

Jul 24th, 2018
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1. public synchronized void enter(Object item){
  2.     while (count == BUFFER_SIZE)
  3.     Thread.yeild();
  4.     ++count;
  5.     buffer[in] = item;
  6.     in = (in+1) % BUFFER_SIZE;
  7. }
  8.  
  9. public synchronized void remove (){
  10.     Object item;
  11.     while (count == 0)
  12.     Thread.yeild();
  13.     --count;
  14.     item = buffer[out]
  15.     out = (out+1) % BUFFER_SIZE;
  16.     return item
  17. }
Advertisement
Add Comment
Please, Sign In to add comment