This commit is contained in:
2024-02-09 23:12:28 +01:00
parent d84ea072ef
commit 5d7694ce0f
11 changed files with 87 additions and 2 deletions

View File

@@ -1,6 +1,10 @@
package Klausur_ueb;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class ThreadTraining {
public static void main(String[] args) {
@@ -38,7 +42,7 @@ class MyThread2 extends Thread {
wait(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (Exception e) {
} catch (Exception ignored) {
}
@@ -58,3 +62,44 @@ class CoolNumber {
}
}
class ExecuteTask {
public static void main(String[] arg) {
ExecutorService executor = Executors.newFixedThreadPool(3);
int sumWartezeit = 1000;
java.util.Random zufall = new java.util.Random();
for (int i = 0; i < 10; i++) {
String name = "" + i;
int wartezeit = zufall.nextInt(1000);
sumWartezeit = sumWartezeit + wartezeit;
Runnable task = new Task(name, wartezeit);
System.out.println("Task " + name + " mit Wartezeit " + wartezeit + " wird an den Threadpool uebergeben.");
executor.execute(task);
}
try {
Thread.sleep(sumWartezeit);
executor.shutdown();
executor.awaitTermination(sumWartezeit, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
}
}
}
class Task implements Runnable {
private String name;
private int wartezeit;
public Task(String name, int wartezeit) {
this.name = name;
this.wartezeit = wartezeit;
}
public void run() {
System.out.println("Task " + name + " beginnt um " + System.currentTimeMillis() + ".");
try {
Thread.sleep(wartezeit);
} catch (InterruptedException e) {
}
System.out.println("Task " + name + " ist fertig um " + System.currentTimeMillis() + " .");
}
}

View File

@@ -0,0 +1,31 @@
//
// Created by jordi on 1/8/24.
//
#include <stdio.h>
// Definition der Date-Struktur
struct Date {
int day;
int month;
int year;
};
// Funktion zur Ausgabe des Datums im Format dd.mm.yyyy
void printDate(struct Date *date) {
printf("%02d.%02d.%04d\n", date->day, date->month, date->year);
}
int main() {
// Erstellen eines Date-Objekts und Zuweisen von Werten
struct Date myDate;
myDate.day = 8;
myDate.month = 1;
myDate.year = 2024;
// Aufrufen der Funktion zum Ausgeben des Datums
printf("Das Datum ist: ");
printDate(&myDate);
return 0;
}

View File

@@ -0,0 +1,9 @@
//
// Created by jordi on 1/8/24.
//
#include <stdio.h>
int main()
{
printf("hallo");
}