Commit 95835471 authored by ElaFHNW's avatar ElaFHNW
Browse files

Incrementer Thread Demo

parent a1bd919a
package annoy1;
public class IncrementerThread extends Thread {
public volatile int i;
public volatile String current = "";
char ch = 'a';
public void run() {
for (;;) { // forever
i++;
current += ch;
IncrementerThread.yield();
}
}
}
package annoy1;
import java.io.IOException;
public class ThreadDemo1 {
public static void main(String[] args) throws IOException {
IncrementerThread it = new IncrementerThread();
it.start();
System.out.println("Keep pressing enter to see the current value of i");
for (int k=0;;k++) {
System.in.read();
System.out.println("k="+ k + " "+ it.i);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment