diff --git a/quasar-core/src/main/java/co/paralleluniverse/fibers/Fiber.java b/quasar-core/src/main/java/co/paralleluniverse/fibers/Fiber.java index 42f646e282..bd553de469 100644 --- a/quasar-core/src/main/java/co/paralleluniverse/fibers/Fiber.java +++ b/quasar-core/src/main/java/co/paralleluniverse/fibers/Fiber.java @@ -140,7 +140,7 @@ private static long nextFiberId() { // private int preemptionCredits; private transient Thread runningThread; private final SuspendableCallable target; - private byte priority; + private int priority; private transient ClassLoader contextClassLoader; private transient AccessControlContext inheritedAccessControlContext; // These are typed as Object because they store JRE-internal ThreadLocalMap objects, which is a package private @@ -176,7 +176,7 @@ public Fiber(String name, FiberScheduler scheduler, int stackSize, SuspendableCa this.task = scheduler != null ? scheduler.newFiberTask(this) : new FiberForkJoinTask(this); this.initialStackSize = stackSize; this.stack = new Stack(this, stackSize > 0 ? stackSize : DEFAULT_STACK_SIZE); - this.priority = (byte)NORM_PRIORITY; + this.priority = NORM_PRIORITY; if (Debug.isDebug()) record(1, "Fiber", "", "Creating fiber name: %s, scheduler: %s, parent: %s, target: %s, task: %s, stackSize: %s", name, scheduler, parent, target, task, stackSize); @@ -230,6 +230,21 @@ public Fiber(String name, int stackSize, SuspendableCallable target) { this(name, defaultScheduler(), stackSize, target); } + /** + * The minimum priority that a fiber can have. + */ + public final static int MIN_PRIORITY = Integer.MIN_VALUE; + + /** + * The default priority that is assigned to a fiber. + */ + public final static int NORM_PRIORITY = 0; + + /** + * The maximum priority that a fiber can have. + */ + public final static int MAX_PRIORITY = Integer.MAX_VALUE; + private static FiberScheduler defaultScheduler() { final Fiber parent = currentFiber(); if (parent == null) @@ -310,7 +325,7 @@ public final Fiber setName(String name) { public Fiber setPriority(int newPriority) { if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) throw new IllegalArgumentException(); - this.priority = (byte) newPriority; + this.priority = newPriority; return this; } diff --git a/quasar-core/src/main/java/co/paralleluniverse/strands/Strand.java b/quasar-core/src/main/java/co/paralleluniverse/strands/Strand.java index 491118a089..967450e698 100644 --- a/quasar-core/src/main/java/co/paralleluniverse/strands/Strand.java +++ b/quasar-core/src/main/java/co/paralleluniverse/strands/Strand.java @@ -55,21 +55,6 @@ public static Strand of(Fiber fiber) { return fiber; } - /** - * The minimum priority that a strand can have. - */ - public final static int MIN_PRIORITY = 1; - - /** - * The default priority that is assigned to a strand. - */ - public final static int NORM_PRIORITY = 5; - - /** - * The maximum priority that a strand can have. - */ - public final static int MAX_PRIORITY = 10; - /** * A strand's running state */ diff --git a/quasar-core/src/test/java/co/paralleluniverse/fibers/FiberTest.java b/quasar-core/src/test/java/co/paralleluniverse/fibers/FiberTest.java index 161c4f58f6..4edb4b007f 100644 --- a/quasar-core/src/test/java/co/paralleluniverse/fibers/FiberTest.java +++ b/quasar-core/src/test/java/co/paralleluniverse/fibers/FiberTest.java @@ -114,20 +114,22 @@ public void run() throws SuspendExecution { } }); - assertThat(fiber.getPriority(), is(Strand.NORM_PRIORITY)); + assertThat(fiber.getPriority(), is(Fiber.NORM_PRIORITY)); fiber.setPriority(3); assertThat(fiber.getPriority(), is(3)); try { - fiber.setPriority(Strand.MAX_PRIORITY + 1); - fail(); + fiber.setPriority(Fiber.MAX_PRIORITY + 1); + if (Fiber.MAX_PRIORITY + 1 != Integer.MIN_VALUE) // Ignore overflow + fail(); } catch (IllegalArgumentException e) { } try { - fiber.setPriority(Strand.MIN_PRIORITY - 1); - fail(); + fiber.setPriority(Fiber.MIN_PRIORITY - 1); + if (Fiber.MIN_PRIORITY - 1 != Integer.MAX_VALUE) // Ignore underflow + fail(); } catch (IllegalArgumentException e) { } }