Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package org.foi.nwtis.marsrnec.zadaca_1;
  7.  
  8. import java.io.IOException;
  9. import java.io.OutputStream;
  10. import org.foi.nwtis.marsrnec.konfiguracije.Konfiguracija;
  11. import static org.foi.nwtis.marsrnec.zadaca_1.ServerSustava.korSoket;
  12. import static org.foi.nwtis.marsrnec.zadaca_1.ServerSustava.radiRezervna;
  13.  
  14. /**
  15. * Dretva RezervnaDretva se pokrece kada se prekoraci dopusteni broj radnih
  16. * dretvi.
  17. *
  18. * @author Marko Srnec
  19. */
  20. public class RezervnaDretva extends Thread {
  21.  
  22. Konfiguracija konf;
  23. OutputStream os;
  24.  
  25. public RezervnaDretva(Konfiguracija konf) {
  26. this.konf = konf;
  27. }
  28.  
  29. @Override
  30. public void interrupt() {
  31. super.interrupt();
  32. }
  33.  
  34. /**
  35. * Dretva ispisuje poruku korisniku o nedostatku slobodne radne dretve i
  36. * zatvara vezu sa korisnikom..
  37. */
  38. @Override
  39. public void run() {
  40. String komanda = "Nepostojanje slobodne radne dretve";
  41. while (radiRezervna) {
  42. try {
  43. os = korSoket.getOutputStream();
  44. os.write(komanda.getBytes());
  45. os.flush();
  46. korSoket.shutdownOutput();
  47. } catch (IOException ex) {
  48. }
  49. try {
  50. os.close();
  51. } catch (IOException ex) {
  52. System.out.println("");
  53. } finally {
  54. try {
  55. sleep(10);
  56. korSoket.close();
  57. radiRezervna = false;
  58. } catch (IOException ex) {
  59. System.out.println("");
  60. } catch (InterruptedException ex) {
  61. }
  62. }
  63. }
  64. }
  65.  
  66. @Override
  67. public synchronized void start() {
  68. super.start();
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement