1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.jdiagnose.concurrent;
15
16 /***
17 * A utility class to set the default capacity of
18 * BoundedChannel
19 * implementations that otherwise require a capacity argument
20 * @see BoundedChannel
21 * [<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p>
22 **/
23
24 public class DefaultChannelCapacity {
25
26 /*** The initial value of the default capacity is 1024 **/
27 public static final int INITIAL_DEFAULT_CAPACITY = 1024;
28
29 /*** the current default capacity **/
30 private static final SynchronizedInt defaultCapacity_ =
31 new SynchronizedInt(INITIAL_DEFAULT_CAPACITY);
32
33 /***
34 * Set the default capacity used in
35 * default (no-argument) constructor for BoundedChannels
36 * that otherwise require a capacity argument.
37 * @exception IllegalArgumentException if capacity less or equal to zero
38 */
39 public static void set(int capacity) {
40 if (capacity <= 0) throw new IllegalArgumentException();
41 defaultCapacity_.set(capacity);
42 }
43
44 /***
45 * Get the default capacity used in
46 * default (no-argument) constructor for BoundedChannels
47 * that otherwise require a capacity argument.
48 * Initial value is <code>INITIAL_DEFAULT_CAPACITY</code>
49 * @see #INITIAL_DEFAULT_CAPACITY
50 */
51 public static int get() {
52 return defaultCapacity_.get();
53 }
54 }