Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- /**
- *
- * @author IT Academy
- */
- public class Nahoda implements Runnable {
- String meno;
- int cas;
- Random r = new Random();
- public Nahoda(String meno) {
- this.meno = meno;
- cas = r.nextInt(9999); // medzi 0-1 sekundami
- }
- // Tato metoda bezi ked zacnu pracovat thready
- @Override
- public void run() {
- try {
- System.out.printf("%s vlakno bude spat %d milisekund\n", meno, cas);
- Thread.sleep(cas); // Ako dlho chces spat
- System.out.printf("%s je ok\n", meno);
- } catch (InterruptedException e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment