package app; |
import java.util.LinkedList; |
import java.util.Queue; |
public class App { |
public static void main(String[] args) { |
new Thread( new Runner( 0 )).start(); |
new Thread( new Runner( 1 )).start(); |
new Thread( new Runner( 2 )).start(); |
new Thread( new Runner( 3 )).start(); |
} |
static class Runner implements Runnable { |
int no; |
static Queue<Character> queue = new LinkedList<>(); |
static { |
for ( int i = 0 ; i < 10 ; i++) { |
queue.offer( 'A' ); |
queue.offer( 'B' ); |
queue.offer( 'C' ); |
queue.offer( 'D' ); |
} |
} |
Runner( int no) { |
this .no = no; |
} |
@Override |
public void run() { |
while (queue.size() != 0 ) { |
synchronized (queue) { |
if (queue.size() != 0 && no == ( 40 - queue.size()) % 4 ) { |
System.out.println(queue.poll()); |
} |
} |
} |
} |
} |
} |