Niti I Prioritet
Niti I Prioritet
frank.start();
mary.start();
chris.start();
}
}
class NamedBytePrinter extends Thread {
public NamedBytePrinter(String name) {
super(name);
}
public void run() {
System.out.println(this.getName() + ": pocinjem!");
for (int b = -10; b < 10; b++) {
System.out.println(this.getName() + ": " + b);
}
System.out.println(this.getName() + ": gotovo!");
}
}
NITI I PRIORITET
public class SelfishRunner extends Thread {
private int tick = 1;
private int num;
public SelfishRunner(int num) {
this.num = num;
}
public void run() {
while (tick < 400000) {
tick++;
if ((tick % 50000) == 0)
System.out.println("Thread #" + num + ", tick = " + tick);
}}}
public class RaceTest {
private final static int NUMRUNNERS = 2;
public static void main(String[] args) {
SelfishRunner[] runners = new SelfishRunner[NUMRUNNERS];
for (int i = 0; i < NUMRUNNERS; i++) {
runners[i] = new SelfishRunner(i);
runners[i].setPriority(2);
}
for (int i = 0; i < NUMRUNNERS; i++)
runners[i].start();
}}
APLETI
import java.applet.*;
import java.awt.*;
APLETI I NITI
import java.awt.Graphics;
import java.util.*;
import java.text.DateFormat;
import java.applet.Applet;
class Skladiste {
private int sadrzaj;
private boolean otkljucano = false;
public synchronized int uzmi() {
while (otkljucano == false) {
try {
wait();
} catch (InterruptedException e) { }
}
otkljucano = false;
return sadrzaj;
}
public synchronized void stavi(int vrednost) {
sadrzaj = vrednost;
otkljucano = true;
notify();
}
}
class Korisnik extends Thread {
private Skladiste mojeskladiste;
private int broj;