Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package org.foi.nwtis.marsrnec.zadaca_1;
- import java.io.IOException;
- import java.io.OutputStream;
- import org.foi.nwtis.marsrnec.konfiguracije.Konfiguracija;
- import static org.foi.nwtis.marsrnec.zadaca_1.ServerSustava.korSoket;
- import static org.foi.nwtis.marsrnec.zadaca_1.ServerSustava.radiRezervna;
- /**
- * Dretva RezervnaDretva se pokrece kada se prekoraci dopusteni broj radnih
- * dretvi.
- *
- * @author Marko Srnec
- */
- public class RezervnaDretva extends Thread {
- Konfiguracija konf;
- OutputStream os;
- public RezervnaDretva(Konfiguracija konf) {
- this.konf = konf;
- }
- @Override
- public void interrupt() {
- super.interrupt();
- }
- /**
- * Dretva ispisuje poruku korisniku o nedostatku slobodne radne dretve i
- * zatvara vezu sa korisnikom..
- */
- @Override
- public void run() {
- String komanda = "Nepostojanje slobodne radne dretve";
- while (radiRezervna) {
- try {
- os = korSoket.getOutputStream();
- os.write(komanda.getBytes());
- os.flush();
- korSoket.shutdownOutput();
- } catch (IOException ex) {
- }
- try {
- os.close();
- } catch (IOException ex) {
- System.out.println("");
- } finally {
- try {
- sleep(10);
- korSoket.close();
- radiRezervna = false;
- } catch (IOException ex) {
- System.out.println("");
- } catch (InterruptedException ex) {
- }
- }
- }
- }
- @Override
- public synchronized void start() {
- super.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement