-
-
Save Youmoo/29f4a525bdab4541631c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Volatility { | |
static int NEXT_IN_LINE = 0; | |
public static void main(String[] args) throws Exception { | |
new CustomerInLine().start(); | |
new Queue().start(); | |
} | |
static class CustomerInLine extends Thread { | |
@Override | |
public void run() { | |
while (true) { | |
if (NEXT_IN_LINE >= 4) { | |
break; | |
} | |
} | |
System.out.format("Great, finally #%d was called, now it is my turn\n",NEXT_IN_LINE); | |
} | |
} | |
static class Queue extends Thread { | |
@Override | |
public void run() { | |
while (NEXT_IN_LINE < 11) { | |
System.out.format("Calling for the customer #%d\n", NEXT_IN_LINE++); | |
try { | |
Thread.sleep(200); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment