LoganBlackisle

Common

Nov 25th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class Faelles {
  4.     private int taeller;
  5.  
  6.     public Faelles() {
  7.         super();
  8.         taeller = 0;
  9.     }
  10.  
  11.     public void tagerRandomTid(int max) {
  12.         Random r = new Random();
  13.         int nymax = Math.abs(r.nextInt()) % max + 1;
  14.         int tal = 0;
  15.         for (int i = 1; i < nymax; i++) {
  16.             for(int j = 0; j < nymax; j++) {
  17.                 tal++;
  18.                 tal--;
  19.             }
  20.         }
  21.     }
  22.  
  23.     public int getTaeller() {
  24.         return taeller;
  25.     }
  26.  
  27.     public synchronized void kritiskSection() {
  28.         int temp = taeller;
  29.         taeller = temp + 1;
  30.         tagerRandomTid(99);
  31.     }
  32. }
Add Comment
Please, Sign In to add comment