while (!isCancelled()) { Runnable cmd; blockingSectionBegin(); cmd = take(); blockingSectionEnd(); updateHeartbeat(); onIdle();
/** {@inheritDoc} */ @Override public void execute(@NotNull Runnable cmd) { stripes[ThreadLocalRandom.current().nextInt(stripes.length)].execute(cmd); }
/** * Starts the stripe. */ void start() { thread = new IgniteThread(igniteInstanceName, name(), this, IgniteThread.GRP_IDX_UNASSIGNED, idx, GridIoPolicy.UNDEFINED); thread.start(); }
stripes[i].start();
while (!isCancelled()) { Runnable cmd; blockingSectionBegin(); cmd = take(); blockingSectionEnd(); active = true; updateHeartbeat(); onIdle();
/** * Checks starvation in striped pool. Maybe too verbose * but this is needed to faster debug possible issues. */ public void checkStarvation() { for (int i = 0; i < stripes.length; i++) { Stripe stripe = stripes[i]; long completedCnt = stripe.completedCnt; boolean active = stripe.active; if (completedCntrs[i] != -1 && completedCntrs[i] == completedCnt && active) { boolean deadlockPresent = U.deadlockPresent(); GridStringBuilder sb = new GridStringBuilder(); sb.a(">>> Possible starvation in striped pool.").a(U.nl()) .a(" Thread name: ").a(stripe.thread.getName()).a(U.nl()) .a(" Queue: ").a(stripe.queueToString()).a(U.nl()) .a(" Deadlock: ").a(deadlockPresent).a(U.nl()) .a(" Completed: ").a(completedCnt).a(U.nl()); U.printStackTrace( stripe.thread.getId(), sb); String msg = sb.toString(); U.warn(log, msg); } if (active || completedCnt > 0) completedCntrs[i] = completedCnt; } }
/** * Execute command. * * @param idx Index. * @param cmd Command. */ public void execute(int idx, Runnable cmd) { if (idx == -1) execute(cmd); else { assert idx >= 0 : idx; stripes[idx % stripes.length].execute(cmd); } }
/** {@inheritDoc} */ @Override public void execute(@NotNull Runnable cmd) { stripes[ThreadLocalRandom.current().nextInt(stripes.length)].execute(cmd); }
/** * @return Return total queue size of all stripes. */ public int queueSize() { int size = 0; for (Stripe stripe : stripes) size += stripe.queueSize(); return size; }
/** * @return Size of queue per stripe. */ public int[] stripesQueueSizes() { int[] res = new int[stripes()]; for (int i = 0; i < res.length; i++) res[i] = stripes[i].queueSize(); return res; }
/** {@inheritDoc} */ @Override public boolean isShutdown() { for (Stripe stripe : stripes) { if (stripe != null && stripe.isCancelled()) return true; } return false; }
/** * Starts the stripe. */ void start() { thread = new IgniteThread(igniteInstanceName, name(), this, IgniteThread.GRP_IDX_UNASSIGNED, idx, GridIoPolicy.UNDEFINED); thread.start(); }
stripes[i].start();
/** * Checks starvation in striped pool. Maybe too verbose * but this is needed to faster debug possible issues. * * @return Flag representing presence of possible starvation in striped pool. */ public boolean detectStarvation() { boolean starvationDetected = false; for (Stripe stripe : stripes) { boolean active = stripe.active; long lastStartedTs = stripe.lastStartedTs; if (active && lastStartedTs + threshold < U.currentTimeMillis()) { starvationDetected = true; boolean deadlockPresent = U.deadlockPresent(); GridStringBuilder sb = new GridStringBuilder(); sb.a(">>> Possible starvation in striped pool.").a(U.nl()) .a(" Thread name: ").a(stripe.thread.getName()).a(U.nl()) .a(" Queue: ").a(stripe.queueToString()).a(U.nl()) .a(" Deadlock: ").a(deadlockPresent).a(U.nl()) .a(" Completed: ").a(stripe.completedCnt).a(U.nl()); U.printStackTrace( stripe.thread.getId(), sb); String msg = sb.toString(); U.warn(log, msg); } } return starvationDetected; }
/** * Execute command. * * @param idx Index. * @param cmd Command. */ public void execute(int idx, Runnable cmd) { if (idx == -1) execute(cmd); else { assert idx >= 0 : idx; stripes[idx % stripes.length].execute(cmd); } }
/** {@inheritDoc} */ @Override public boolean isShutdown() { for (Stripe stripe : stripes) { if (stripe != null && stripe.isCancelled()) return true; } return false; }
/** * @return Return total queue size of all stripes. */ public int queueSize() { int size = 0; for (Stripe stripe : stripes) size += stripe.queueSize(); return size; }
/** * @return Size of queue per stripe. */ public int[] stripesQueueSizes() { int[] res = new int[stripes()]; for (int i = 0; i < res.length; i++) res[i] = stripes[i].queueSize(); return res; }