diff --git a/.gitignore b/.gitignore index ea65961746f43b4a8d3e74a714cd6031aabea5ae..89ed1a9a758c435d7d3262a05f00ac3be10c2306 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build.xml dist/ manifest.mf nbproject/ +n-ary tree/ diff --git a/5. labor/Producer/src/Application.java b/5. labor/Producer/src/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..9e702d5ee6ca5554e04dfde640e7dbb4b6671805 --- /dev/null +++ b/5. labor/Producer/src/Application.java @@ -0,0 +1,13 @@ +public class Application { + public static void main(String args[]) throws InterruptedException + { + Fifo storage = new Fifo(); + Producer prod = new Producer(storage, "producer", 250); + Consumer con = new Consumer(storage, "consumer", 500); + + Thread t1 = new Thread(prod); + Thread t2 = new Thread(con); + t1.start(); + t2.start(); + } +} \ No newline at end of file diff --git a/5. labor/Producer/src/Consumer.java b/5. labor/Producer/src/Consumer.java new file mode 100644 index 0000000000000000000000000000000000000000..4da710e633aae4d7dc663866fd3c263b4953acdc --- /dev/null +++ b/5. labor/Producer/src/Consumer.java @@ -0,0 +1,31 @@ +import static java.lang.Thread.sleep; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Consumer implements Runnable{ + Fifo storage; + String message; + int sleepTime; + public Consumer(Fifo f, String s, int n) + { + storage = f; + message = s; + sleepTime = n; + } + + @Override + public void run() + { + while(true) + { + try { + System.out.println("consumed " + message + " " + + storage.get() + " " + + System.currentTimeMillis()); + sleep(sleepTime); + } catch (InterruptedException ex) { + Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex); + } + } + } +} diff --git a/5. labor/Producer/src/Fifo.java b/5. labor/Producer/src/Fifo.java new file mode 100644 index 0000000000000000000000000000000000000000..d4d4bfc466d6eca2bd6c347c632411f21f24f82e --- /dev/null +++ b/5. labor/Producer/src/Fifo.java @@ -0,0 +1,31 @@ +import java.util.ArrayList; + +public class Fifo{ + protected ArrayList<String> s; + { + s = new ArrayList<>(10); //csak azért, hogy használjak már inicializáló blokkot is + } + public synchronized void put(String e) throws InterruptedException + { + if(s.size()>=10) + { + this.wait(); + } + this.notifyAll(); + s.add(e); + System.out.println("produced" + " " + e + " " + + System.currentTimeMillis()); + } + + synchronized String get() throws InterruptedException + { + if(s.size()<=0) + { + this.wait(); + } + this.notifyAll(); + String ret=s.get(0); + s.remove(ret); + return ret; + } +} diff --git a/5. labor/Producer/src/Producer.java b/5. labor/Producer/src/Producer.java new file mode 100644 index 0000000000000000000000000000000000000000..87edc1c1b5af6e55c18840eecf14ee439f6ac295 --- /dev/null +++ b/5. labor/Producer/src/Producer.java @@ -0,0 +1,41 @@ +import static java.lang.Thread.sleep; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Producer implements Runnable{ + private String message; + private Fifo storage; + private int sleepTime; + + public Producer(Fifo f, String s, int n) + { + message = s; + storage = f; + sleepTime = n; + } + + public void go() throws InterruptedException + { + int i=0; + while(true) + { + storage.put(message + " " + i++); + try { + sleep(sleepTime); + } + catch (InterruptedException ex) { + Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + @Override + public void run() + { + try { + this.go(); + } catch (InterruptedException ex) { + Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/5. labor/java_5_szalak_tasks.pdf b/5. labor/java_5_szalak_tasks.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a81fb48489bf46d6a0fcb38e57f7943215753402 Binary files /dev/null and b/5. labor/java_5_szalak_tasks.pdf differ diff --git a/prog3_5_utilities_p1.pdf b/prog3_5_utilities_p1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f136d9b05c8f38a026701afcb26c2087910c9f68 Binary files /dev/null and b/prog3_5_utilities_p1.pdf differ diff --git a/prog3_6_threads_p1.pdf b/prog3_6_threads_p1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e4bc3c2c18191d95d6ccfa1ae83dd14261e98bfc Binary files /dev/null and b/prog3_6_threads_p1.pdf differ