@Override // Keep subtracting an amount from the account public void run() { while (true) { account.withdraw((int) (Math.random() * 10) + 1); } }
/** * @param cctx Context. * @param id Partition ID. */ @SuppressWarnings("ExternalizableWithoutPublicNoArgConstructor") GridDhtLocalPartition(GridCacheContext cctx, int id) { assert cctx != null; this.id = id; this.cctx = cctx; log = U.logger(cctx.kernalContext(), logRef, this); rent = new GridFutureAdapter<Object>() { @Override public String toString() { return "PartitionRentFuture [part=" + GridDhtLocalPartition.this + ", map=" + map + ']'; } }; map = new ConcurrentHashMap8<>(cctx.config().getStartSize() / cctx.affinity().partitions()); int delQueueSize = CU.isSystemCache(cctx.name()) ? 100 : Math.max(MAX_DELETE_QUEUE_SIZE / cctx.affinity().partitions(), 20); rmvQueue = new GridCircularBuffer<>(U.ceilPow2(delQueueSize)); }
/** * Creates a new map with the same mappings as the given map. The map is created with a capacity * of twice the number of mappings in the given map or 11 (whichever is greater), and a default * load factor. * * @param t the map */ public ConcurrentHashMap(Map<? extends K, ? extends V> t) { this( Math.max((int) (t.size() / DEFAULT_LOAD_FACTOR) + 1, 11), DEFAULT_LOAD_FACTOR, DEFAULT_SEGMENTS); putAll(t); }
@Override public void setHeartbeatInterval(int msHeartbeatInterval) { synchronized (this.concurrentClientLock) { synchronized (this.callbackLock) { this.msHeartbeatInterval = Math.max(0, msHeartbeatInterval); } } }
@Override // Keep adding an amount to the account public void run() { try { // Purposely delay it to let the withdraw method proceed while (true) { account.deposit((int) (Math.random() * 10) + 1); Thread.sleep(1000); } } catch (InterruptedException ex) { ex.printStackTrace(); } }
public void followUpdate() { ObjectStub followObj = (ObjectStub) followTarget.getEntity(Namespace.MOB); Point followLoc = followObj.getWorldNode().getLoc(); InterpolatedWorldNode node = obj.getWorldNode(); Point myLoc = node.getLoc(); long oid = obj.getOid(); float fdist = Point.distanceTo(followLoc, destLoc); float dist = Point.distanceTo(followLoc, myLoc); if (Log.loggingDebug) Log.debug( "BaseBehavior.followUpdate: oid = " + oid + "; myLoc = " + myLoc + "; followLoc = " + followLoc + "; fdist = " + fdist + "; dist = " + dist); long msToSleep = (long) 500; // If the new target location is more than a meter from // the old one, create a new path. if (fdist > 1000) { long msToDest = setupPathInterpolator(oid, myLoc, followLoc, true, node.getFollowsTerrain()); destLoc = followLoc; msToSleep = msToDest == 0 ? (long) 500 : Math.min((long) 500, msToDest); } // Else if we're interpolating, interpolate the current path else if (interpolatingPath) { interpolatePath(); if (Log.loggingDebug) Log.debug( "baseBehavior.followUpdate: oid = " + oid + "; interpolated myLoc = " + obj.getWorldNode().getLoc()); } scheduleMe(interpolatingPath ? msToSleep : pathState.pathTimeRemaining()); }
static void realMain(String[] args) throws Throwable { // jmap doesn't work on Windows if (System.getProperty("os.name").startsWith("Windows")) return; final String childClassName = Job.class.getName(); final String classToCheckForLeaks = Job.classToCheckForLeaks(); final String uniqueID = String.valueOf(new Random().nextInt(Integer.MAX_VALUE)); final String[] jobCmd = { java, "-Xmx8m", "-classpath", System.getProperty("test.classes", "."), childClassName, uniqueID }; final Process p = new ProcessBuilder(jobCmd).start(); final String childPid = match( commandOutputOf(jps, "-m"), "(?m)^ *([0-9]+) +\\Q" + childClassName + "\\E *" + uniqueID + "$", 1); final int n0 = objectsInUse(p, childPid, classToCheckForLeaks); final int n1 = objectsInUse(p, childPid, classToCheckForLeaks); equal(p.waitFor(), 0); equal(p.exitValue(), 0); failed += p.exitValue(); // Check that no objects were leaked. System.out.printf("%d -> %d%n", n0, n1); check(Math.abs(n1 - n0) < 2); // Almost always n0 == n1 check(n1 < 20); drainers.shutdown(); }
public int getPauseTime() { return (int) (Math.max(1000, 5000 * random.nextDouble())); }
private void scheduleRecheck() { if (!isDone()) { GridTimeoutObject old = timeoutObj; if (old != null) cctx.kernalContext().timeout().removeTimeoutObject(old); GridTimeoutObject timeoutObj = new GridTimeoutObjectAdapter( cctx.gridConfig().getNetworkTimeout() * Math.max(1, cctx.gridConfig().getCacheConfiguration().length)) { @Override public void onTimeout() { cctx.kernalContext() .closure() .runLocalSafe( new Runnable() { @Override public void run() { if (isDone()) return; if (!enterBusy()) return; try { U.warn( log, "Retrying preload partition exchange due to timeout [done=" + isDone() + ", dummy=" + dummy + ", exchId=" + exchId + ", rcvdIds=" + F.id8s(rcvdIds) + ", rmtIds=" + F.id8s(rmtIds) + ", remaining=" + F.id8s(remaining()) + ", init=" + init + ", initFut=" + initFut.isDone() + ", ready=" + ready + ", replied=" + replied + ", added=" + added + ", oldest=" + U.id8(oldestNode.get().id()) + ", oldestOrder=" + oldestNode.get().order() + ", evtLatch=" + evtLatch.getCount() + ", locNodeOrder=" + cctx.localNode().order() + ", locNodeId=" + cctx.localNode().id() + ']', "Retrying preload partition exchange due to timeout."); recheck(); } finally { leaveBusy(); } } }); } }; this.timeoutObj = timeoutObj; cctx.kernalContext().timeout().addTimeoutObject(timeoutObj); } }
protected void scheduleMe(long timeToDest) { long ms = Math.min((long) 500, timeToDest); // if (Log.loggingDebug) // Log.debug("BaseBehavior.scheduleMe: ms = " + ms); Engine.getExecutor().schedule(this, ms, TimeUnit.MILLISECONDS); }