Advertisement
Andrew2002

Lab4-4

Jun 23rd, 2021
1,160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.19 KB | None | 0 0
  1. // var. 2361
  2. public class Lab4 {
  3.   public static void main(String[] args) {
  4.     C a = new C();
  5.     C b = new E();
  6.     E c = new E();
  7.     a.z42();
  8.     b.z36();
  9.     c.z27();
  10.     c.z3();
  11.     b.z9();
  12.     b.z40();
  13.     c.z32();
  14.     a.z18();
  15.     a.z10();
  16.     c.z31();
  17.     b.z24(a);
  18.     a.z24(b);
  19.     a.z24(c);
  20.     c.z15();
  21.     c.z38();
  22.     c.z23();
  23.     Thread t = new Thread(new Runnable() {
  24.       public void run() {
  25.         while(true) {
  26.           try {
  27.              E d = new E();
  28.              d.z47();
  29.              Thread.sleep(9);
  30.           } catch(Exception e) {
  31.             // Do nothing
  32.           }
  33.         }
  34.       }
  35.     });
  36.     t.start();
  37.   }
  38. }
  39. class C {
  40.   int z21;
  41.   int z5;
  42.   int z44;
  43.   int z16;
  44.   int z4;
  45.   long z14;
  46.   long z22;
  47.   long z45;
  48.   java.io.ObjectOutputStream printOutput;
  49.   java.io.ObjectOutputStream fileWrtr;
  50.   int[] z7 = {3, -1, -1, -2};
  51.   int[] z2 = {-1, 1, 1, 2, 3};
  52.   int[] z41 = {-2, 3, 1, 0};
  53.   static java.util.Map<java.net.URL,byte[]> cache = new java.util.HashMap<>();
  54.   static int z13;
  55.   static int z34;
  56.   static int z48;
  57.   static int z17;
  58.   static int z50;
  59.   java.util.List<String> z20 = new java.util.ArrayList<>();
  60.   java.util.List<String> z6 = new java.util.ArrayList<>();
  61.   java.util.List<String> z43 = new java.util.ArrayList<>();
  62.   public C() {
  63.     z21 = 2;
  64.     z5 = 0;
  65.     z44 = 1;
  66.     z16 = 1;
  67.     z4 = 1;
  68.     z14 = 5L;
  69.     z22 = 6L;
  70.     z45 = 5L;
  71.     try {
  72.         printOutput = new java.io.ObjectOutputStream(new java.io.FileOutputStream("printOutput.txt"));
  73.         fileWrtr = new java.io.ObjectOutputStream(new java.io.FileOutputStream("fileWrtr.txt"));
  74.     } catch (java.lang.Exception e) {
  75.       // Do nothing
  76.     }
  77.   }
  78.   public void init() {
  79.     try {
  80.       if (printOutput == null) printOutput = new java.io.ObjectOutputStream(new java.io.FileOutputStream("printOutput.txt"));
  81.       System.out.println("Thread : " + Thread.currentThread() + ", printOutput = " + printOutput);
  82.     } catch(Exception e) {
  83.       // Ignore it
  84.     }
  85.     try {
  86.       if (fileWrtr == null) fileWrtr = new java.io.ObjectOutputStream(new java.io.FileOutputStream("fileWrtr.txt"));
  87.       System.out.println("Thread : " + Thread.currentThread() + ", fileWrtr = " + fileWrtr);
  88.     } catch(Exception e) {
  89.       // Ignore it
  90.     }
  91.   }
  92.   public byte[] getValueFromCache(String s) {
  93.     try {
  94.       java.net.URL url = new java.net.URL(s);
  95.       if(!cache.containsKey(url)) {
  96.         cache.put(url, new byte[1572864]);
  97.       }
  98.       return cache.get(url);
  99.     } catch (Exception e) {
  100.       System.out.println("Error: invalid URL!");
  101.       return null;
  102.     }
  103.   }
  104.   public void z42() {
  105.     Thread t = new Thread(new Runnable() {
  106.       public void run() {
  107.         init();
  108.         int i = 0;
  109.         while(true) {
  110.           i++;
  111.           try {
  112.             synchronized(fileWrtr) {
  113.               fileWrtr.writeObject("метод z42 в классе C (#" + String.valueOf(i) + ")");
  114.               Thread.sleep(6);
  115.               fileWrtr.flush();
  116.               fileWrtr.reset();
  117.             }
  118.           } catch(Exception e) {
  119.             // Do nothing
  120.           }
  121.         }
  122.       }
  123.     });
  124.     t.start();
  125.   }
  126.   public void z36() {
  127.     Thread t = new Thread(new Runnable() {
  128.       public void run() {
  129.         init();
  130.         int i = 0;
  131.         while(true) {
  132.           i++;
  133.           try {
  134.             synchronized(printOutput) {
  135.               printOutput.writeObject("метод z36 в классе C (#" + String.valueOf(i) + ")");
  136.               Thread.sleep(5);
  137.               printOutput.reset();
  138.             }
  139.           } catch(Exception e) {
  140.             // Do nothing
  141.           }
  142.         }
  143.       }
  144.     });
  145.     t.start();
  146.   }
  147.   public void z27() {
  148.     Thread t = new Thread(new Runnable() {
  149.       public void run() {
  150.         init();
  151.         int i = 0;
  152.         while(true) {
  153.           i++;
  154.           try {
  155.             synchronized(fileWrtr) {
  156.               fileWrtr.writeObject("метод z27 в классе C (#" + String.valueOf(i) + ")");
  157.               Thread.sleep(5);
  158.               fileWrtr.flush();
  159.               fileWrtr.reset();
  160.             }
  161.           } catch(Exception e) {
  162.             // Do nothing
  163.           }
  164.         }
  165.       }
  166.     });
  167.     t.start();
  168.   }
  169.   public void z3() {
  170.     Thread t = new Thread(new Runnable() {
  171.       public void run() {
  172.         init();
  173.         int i = 0;
  174.         while(true) {
  175.           i++;
  176.           try {
  177.             synchronized(printOutput) {
  178.               printOutput.writeObject("метод z3 в классе C (#" + String.valueOf(i) + ")");
  179.               Thread.sleep(6);
  180.               printOutput.flush();
  181.               printOutput.reset();
  182.             }
  183.           } catch(Exception e) {
  184.             // Do nothing
  185.           }
  186.         }
  187.       }
  188.     });
  189.     t.start();
  190.   }
  191.   public void z9() {
  192.     Thread t = new Thread(new Runnable() {
  193.       public void run() {
  194.         init();
  195.         int i = 0;
  196.         while(true) {
  197.           i++;
  198.           try {
  199.             synchronized(printOutput) {
  200.               printOutput.writeObject("метод z9 в классе C (#" + String.valueOf(i) + ")");
  201.               Thread.sleep(6);
  202.               printOutput.reset();
  203.             }
  204.           } catch(Exception e) {
  205.             // Do nothing
  206.           }
  207.         }
  208.       }
  209.     });
  210.     t.start();
  211.   }
  212.   public void z40() {
  213.     Thread t = new Thread(new Runnable() {
  214.       public void run() {
  215.         init();
  216.         int i = 0;
  217.         while(true) {
  218.           i++;
  219.           try {
  220.             synchronized(printOutput) {
  221.               printOutput.writeObject("метод z40 в классе C (#" + String.valueOf(i) + ")");
  222.               Thread.sleep(5);
  223.               printOutput.flush();
  224.               printOutput.reset();
  225.             }
  226.           } catch(Exception e) {
  227.             // Do nothing
  228.           }
  229.         }
  230.       }
  231.     });
  232.     t.start();
  233.   }
  234.   public static void z32() {
  235.     System.out.println("метод z32 в классе C");
  236.     System.out.println(z13);
  237.   }
  238.   public static void z18() {
  239.     System.out.println("метод z18 в классе C");
  240.     System.out.println((z13 - 2));
  241.   }
  242.   public static void z10() {
  243.     System.out.println("метод z10 в классе C");
  244.     System.out.println(z34);
  245.   }
  246.   public static void z31() {
  247.     System.out.println("метод z31 в классе C");
  248.     System.out.println((z34 - 1));
  249.   }
  250.   public void z24(C r) {
  251.     r.z42();
  252.   }
  253.   public void z24(E r) {
  254.     r.z36();
  255.   }
  256. }
  257. class E extends C {
  258.   public E() {
  259.     z21 = 3;
  260.     z5 = 9;
  261.     z4 = 7;
  262.     z14 = 1L;
  263.     z22 = 2L;
  264.   }
  265.   public void z42() {
  266.     Thread t = new Thread(new Runnable() {
  267.       public void run() {
  268.         init();
  269.         int i = 0;
  270.         while(true) {
  271.           i++;
  272.           try {
  273.             synchronized(fileWrtr) {
  274.               fileWrtr.writeObject("метод z42 в классе E (#" + String.valueOf(i) + ")");
  275.               Thread.sleep(5);
  276.               fileWrtr.reset();
  277.             }
  278.           } catch(Exception e) {
  279.             // Do nothing
  280.           }
  281.         }
  282.       }
  283.     });
  284.     t.start();
  285.   }
  286.   public void z27() {
  287.     Thread t = new Thread(new Runnable() {
  288.       public void run() {
  289.         init();
  290.         int i = 0;
  291.         while(true) {
  292.           i++;
  293.           try {
  294.             synchronized(printOutput) {
  295.               printOutput.writeObject("метод z27 в классе E (#" + String.valueOf(i) + ")");
  296.               Thread.sleep(8);
  297.               printOutput.reset();
  298.             }
  299.           } catch(Exception e) {
  300.             // Do nothing
  301.           }
  302.         }
  303.       }
  304.     });
  305.     t.start();
  306.   }
  307.   public void z3() {
  308.     Thread t = new Thread(new Runnable() {
  309.       public void run() {
  310.         init();
  311.         int i = 0;
  312.         while(true) {
  313.           i++;
  314.           try {
  315.             synchronized(printOutput) {
  316.               printOutput.writeObject("метод z3 в классе E (#" + String.valueOf(i) + ")");
  317.               Thread.sleep(12);
  318.               printOutput.flush();
  319.               printOutput.reset();
  320.             }
  321.           } catch(Exception e) {
  322.             // Do nothing
  323.           }
  324.         }
  325.       }
  326.     });
  327.     t.start();
  328.   }
  329.   public void z9() {
  330.     Thread t = new Thread(new Runnable() {
  331.       public void run() {
  332.         init();
  333.         int i = 0;
  334.         while(true) {
  335.           i++;
  336.           try {
  337.             synchronized(printOutput) {
  338.               printOutput.writeObject("метод z9 в классе E (#" + String.valueOf(i) + ")");
  339.               Thread.sleep(5);
  340.               printOutput.flush();
  341.               printOutput.reset();
  342.             }
  343.           } catch(Exception e) {
  344.             // Do nothing
  345.           }
  346.         }
  347.       }
  348.     });
  349.     t.start();
  350.   }
  351.   public void z15() {
  352.     Thread t = new Thread(new Runnable() {
  353.       public void run() {
  354.         while(true) {
  355.           try {
  356.             synchronized(cache) {
  357.               getValueFromCache("https://www.google.com");
  358.               Thread.sleep(14);
  359.             }
  360.           } catch(Exception e) {
  361.             // Do nothing
  362.           }
  363.         }
  364.       }
  365.     });
  366.     t.start();
  367.   }
  368.   public void z38() {
  369.     Thread t = new Thread(new Runnable() {
  370.       public void run() {
  371.         while(true) {
  372.           try {
  373.             synchronized(cache) {
  374.               getValueFromCache("https://www.google.com");
  375.               Thread.sleep(7);
  376.             }
  377.           } catch(Exception e) {
  378.             // Do nothing
  379.           }
  380.         }
  381.       }
  382.     });
  383.     t.start();
  384.   }
  385.   public void z23() {
  386.     Thread t = new Thread(new Runnable() {
  387.       public void run() {
  388.         while(true) {
  389.           try {
  390.             synchronized(cache) {
  391.               getValueFromCache("https://www.google.com");
  392.               Thread.sleep(10);
  393.             }
  394.           } catch(Exception e) {
  395.             // Do nothing
  396.           }
  397.         }
  398.       }
  399.     });
  400.     t.start();
  401.   }
  402.   public static void z32() {
  403.     System.out.println("метод z32 в классе E");
  404.     System.out.println(z13--);
  405.   }
  406.   public static void z18() {
  407.     System.out.println("метод z18 в классе E");
  408.     System.out.println(z34);
  409.   }
  410.   public static void z10() {
  411.     System.out.println("метод z10 в классе E");
  412.     System.out.println((z34 - 5));
  413.   }
  414.   public static void z31() {
  415.     System.out.println("метод z31 в классе E");
  416.     System.out.println(z34);
  417.   }
  418.   public void z25() {
  419.     for(int i = 0; i < 6; i++) {
  420.       this.z43.add(String.valueOf(System.nanoTime()));
  421.       // System.out.println(this.z43.size());
  422.     }
  423.   }
  424.   public void z8() {
  425.     for(int i = 0; i < 6; i++) {
  426.       this.z6.add(String.valueOf(System.nanoTime()));
  427.       // System.out.println(this.z6.size());
  428.     }
  429.   }
  430.   public void z47() {
  431.     for(int i = 0; i < 9; i++) {
  432.       this.z20.add(String.valueOf(System.nanoTime()));
  433.       // System.out.println(this.z20.size());
  434.     }
  435.   }
  436.   public void z19() {
  437.     for(int i = 0; i < 9; i++) {
  438.       this.z6.add(String.valueOf(System.nanoTime()));
  439.       // System.out.println(this.z6.size());
  440.     }
  441.   }
  442.   public void z24(C r) {
  443.     r.z27();
  444.   }
  445.   public void z24(E r) {
  446.     r.z3();
  447.   }
  448. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement