Browse Source

Änderungen 05.12.2023 um 14:44

master
leonmcfly 1 year ago
parent
commit
f6668dfce7

+ 1
- 1
src/DiningPhilosophers/Fork.java View File

@@ -24,7 +24,7 @@ public class Fork {
}catch (InterruptedException e){
System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert");
}
return true
return true;
}
}


+ 34
- 0
src/DiningPhilosophers/Philosopher.java View File

@@ -13,6 +13,40 @@ public class Philosopher implements Runnable{

@Override
public void run(){
while(true) {
allocateForks();
System.out.println("Philosopher " + id + " is eating");
try{
Thread.sleep(2000);
}catch (Exception e){

}
left.put();
right.put();
System.out.println("Philosopher " + id + " finished eating");


}
}

protected void allocateForks() {
Fork firstFork, secondFork;

if (left.getId() < right.getId()){
firstFork = left;
secondFork = right;
} else {
firstFork = right;
secondFork = left;
}

System.out.println("Philosopher " + id + " is trying to take Fork " + firstFork.getId());
while (!firstFork.take())
Thread.yield();
System.out.println("Philosopher " + id + " got Fork " + firstFork.getId());
System.out.println("Philosopher " + id + " is trying to take Fork " + secondFork.getId());
while (!secondFork.take())
Thread.yield();
System.out.println("Philosopher " + id + " got Fork " + secondFork.getId());
}
}

+ 1
- 0
src/DiningPhilosophers/Table.java View File

@@ -15,6 +15,7 @@ public class Table {
};

for (Philosopher philosopher : philosophers) {

Thread t = new Thread(philosopher);
t.start();
}

+ 26
- 0
src/DistributedSorter/SorterClient.java View File

@@ -0,0 +1,26 @@
package Prog3.src.DistributedSorter;

import java.util.Scanner;

public class SorterClient {
public static void main(String[] args) {
SorterClient client = new SorterClient();
client.run();
}

public void run(){
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(line.isEmpty())
break;
line = sort(line);
System.out.println(line);
}
scanner.close();
}

private String sort(String line){

}
}

Loading…
Cancel
Save