Finished assigment
commit
54e159b6d5
|
@ -0,0 +1,11 @@
|
|||
class MyWorker implements Runnable {
|
||||
private Thread self;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.self = Thread.currentThread();
|
||||
while (true) {
|
||||
System.out.println(this.self.getName() + ": ID => " + this.self.threadId());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
class MyWorkerCoop implements Runnable {
|
||||
private Thread self;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.self = Thread.currentThread();
|
||||
while (true) {
|
||||
System.out.println(this.self.getName() + ": ID => " + this.self.threadId());
|
||||
Thread.yield();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
public class Starter {
|
||||
static int WORKERS = 200;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
public class StarterInner {
|
||||
static int WORKERS = 200;
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (var i = 0; i < Starter.WORKERS; i++) {
|
||||
var t = new Thread(new Runnable() {
|
||||
private Thread self;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.self = Thread.currentThread();
|
||||
while(true) {
|
||||
System.out.println(this.self.getName() + ": ID => " + this.self.threadId());
|
||||
}
|
||||
}
|
||||
}, String.format("Worker-%03d", i));
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
public class StarterLambda {
|
||||
static int WORKERS = 200;
|
||||
|
||||
public static void main(String... args) {
|
||||
for (var i = 0; i < Starter.WORKERS; i++) {
|
||||
var t = new Thread(
|
||||
() -> {
|
||||
var self = Thread.currentThread();
|
||||
while(true) {
|
||||
System.out.println(self.getName() + ": ID => " + self.threadId());
|
||||
}
|
||||
},String.format("Worker-%03d", i));
|
||||
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue