Kai Sellmann 2024-10-23 21:05:17 +02:00
parent 5edbe0efd7
commit a053915cea
7 changed files with 99 additions and 1 deletions

24
.classpath 100644
View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="eigenes/src"/>
<classpathentry kind="src" path="src/pp.01.01-Inheritance_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.01.01-Inheritance/src/main/java"/>
<classpathentry kind="src" path="src/pp.01.02-Runnable_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.01.02-Runnable/src/main/java"/>
<classpathentry kind="src" path="src/pp.01.03-EndThread_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.01.03-EndThread/src/main/java"/>
<classpathentry kind="src" path="src/pp.02.01-MemoryBarrier_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.02.01-MemoryBarrier/src/main/java"/>
<classpathentry kind="src" path="src/pp.02.02-ThreadLocal_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.02.02-ThreadLocal/src/main/java"/>
<classpathentry kind="src" path="src/pp.02.03-Lock_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.02.03-Lock/src/main/java"/>
<classpathentry kind="src" path="src/pp.03.01-SynchPhilosopher_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.03.01-SynchPhilosopher/src/main/java"/>
<classpathentry kind="src" path="src/pp.03.02-BoundedQueueWaitNotify_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.03.02-BoundedQueueWaitNotify/src/main/java"/>
<classpathentry kind="src" path="src/pp.03.03-BoundedQueueAwaitSignal_solution/src/main/java"/>
<classpathentry kind="src" path="src/pp.03.03-BoundedQueueAwaitSignal/src/main/java"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
/bin/

17
.project 100644
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PP-Labs_WS-2024-2025</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -6,7 +6,7 @@ public class Starter {
public static void main(String... args) {
for (var i = 0; i < Starter.WORKERS; i++) {
var t = new Thread(new MyWorker(), String.format("Worker-%03d", i));
var t = new Thread(new MyWorkerCoop(), String.format("Worker-%03d", i));
t.start();
}
}

View File

@ -0,0 +1,24 @@
package pp;
public class StarterInner {
static int WORKERS = 200;
public static void main(String... args) {
for (var i = 0; i < Starter.WORKERS; i++) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Thread t = Thread.currentThread();
while (true) {
System.out.println(t.getName() + ": ID => " + t.threadId());
}
}
}, String.format("Worker-%03d", i));
t.start();
}
}
}

View File

@ -0,0 +1,20 @@
package pp;
public class StarterLambda {
static int WORKERS = 200;
public static void main(String... args) {
for (var i = 0; i < WORKERS; i++) {
Thread t = new Thread(() -> {
// Verwenden von Thread.currentThread() als Lambda-Ausdruck
Thread t1 = Thread.currentThread();
while (true) {
System.out.println(t1.getName() + ": ID => " + t1.threadId());
}
}, String.format("Worker-%03d", i));
t.start();
}
}
}

View File

@ -12,5 +12,17 @@ public class Runner {
e.printStackTrace(System.err);
});
thread.start();
Thread s = new Thread( () -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Task wird gestoppt.");
task.stopRequest();
});
s.start();
}
}