Browse Source

Änderungen 05.12.2023 um 14:44

master
leonmcfly 11 months ago
parent
commit
f6668dfce7

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

}catch (InterruptedException e){ }catch (InterruptedException e){
System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert"); System.out.println("Gabel mit ID: " + id + " hat nicht funktioniert");
} }
return true
return true;
} }
} }



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



@Override @Override
public void run(){ 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

}; };


for (Philosopher philosopher : philosophers) { for (Philosopher philosopher : philosophers) {

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

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

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