实现BlockingQueue
看了下JDK的源代码实现,模拟了一下ArrayBlockQueue,代码如下:
size : 1, Thread-0 put 15size : 2, Thread-0 put 0size : 3, Thread-0 put 18size : 4, Thread-0 put 9size : 5, Thread-0 put 6size : 4, Thread-3 get 15size : 3, Thread-5 get 0size : 2, Thread-5 get 18size : 1, Thread-5 get 9size : 0, Thread-5 get 6size : 1, Thread-1 put 12size : 0, Thread-4 get 12size : 1, Thread-0 put 3size : 2, Thread-2 put 2size : 3, Thread-2 put 13size : 4, Thread-2 put 12size : 5, Thread-2 put 14size : 4, Thread-5 get 3size : 3, Thread-5 get 2size : 2, Thread-5 get 13size : 1, Thread-5 get 12size : 0, Thread-5 get 14size : 1, Thread-1 put 0size : 2, Thread-1 put 3size : 3, Thread-1 put 19size : 4, Thread-1 put 13size : 5, Thread-1 put 2size : 4, Thread-4 get 0size : 3, Thread-4 get 3size : 2, Thread-4 get 19size : 1, Thread-4 get 13size : 0, Thread-4 get 2size : 1, Thread-2 put 1size : 2, Thread-2 put 9size : 3, Thread-2 put 10size : 4, Thread-2 put 14size : 5, Thread-2 put 3size : 4, Thread-5 get 1size : 3, Thread-3 get 9size : 2, Thread-3 get 10size : 1, Thread-3 get 14size : 0, Thread-3 get 3size : 1, Thread-1 put 17size : 2, Thread-1 put 14size : 3, Thread-1 put 1size : 4, Thread-1 put 10size : 3, Thread-4 get 17size : 2, Thread-4 get 14size : 1, Thread-4 get 1size : 0, Thread-4 get 10size : 1, Thread-2 put 6size : 2, Thread-0 put 1size : 3, Thread-0 put 14size : 4, Thread-0 put 9size : 5, Thread-0 put 4size : 4, Thread-3 get 6size : 3, Thread-3 get 1size : 2, Thread-3 get 14size : 1, Thread-3 get 9size : 0, Thread-3 get 4