/** * Prevents any operations from occurring on this map while the * given {@link Runnable} executes. This method can be used, for * instance, to execute a bulk operation atomically: * * <pre> * staticBucketMapInstance.atomic(new Runnable() { * public void run() { * staticBucketMapInstance.putAll(map); * } * }); * </pre> * * It can also be used if you need a reliable iterator: * * <pre> * staticBucketMapInstance.atomic(new Runnable() { * public void run() { * Iterator iterator = staticBucketMapInstance.iterator(); * while (iterator.hasNext()) { * foo(iterator.next(); * } * } * }); * </pre> * * <b>Implementation note:</b> This method requires a lot of time * and a ton of stack space. Essentially a recursive algorithm is used * to enter each bucket's monitor. If you have twenty thousand buckets * in your map, then the recursive method will be invoked twenty thousand * times. You have been warned. * * @param r the code to execute atomically */ public void atomic(java.lang.Runnable r) { if (r == null) { throw new java.lang.NullPointerException(); } atomic(r, 0); }
private void atomic(java.lang.Runnable r, int bucket) { if (bucket >= buckets.Length) { r.run(); return; } lock (locks[bucket]) { atomic(r, bucket + 1); } }
protected InvocationEvent(Object source, int id, java.lang.Runnable runnable, Object notifier, bool catchExceptions) : base(source, id) { // awt.18C=Cannot invoke null runnable System.Diagnostics.Debug.Assert(runnable != null, "Cannot invoke null runnable"); //$NON-NLS-1$ if (source == null) { // awt.18D=Source is null throw new java.lang.IllegalArgumentException("Source is null"); //$NON-NLS-1$ } this.runnable = runnable; this.notifier = notifier; this.catchExceptions = catchExceptions; throwable = null; when = java.lang.SystemJ.currentTimeMillis(); }
protected InvocationEvent(Object source, int id, java.lang.Runnable runnable, Object notifier, bool catchExceptions) : base(source, id) { // awt.18C=Cannot invoke null runnable System.Diagnostics.Debug.Assert(runnable != null, "Cannot invoke null runnable"); //$NON-NLS-1$ if (source == null) { // awt.18D=Source is null throw new java.lang.IllegalArgumentException("Source is null"); //$NON-NLS-1$ } this.runnable = runnable; this.notifier = notifier; this.catchExceptions = catchExceptions; throwable = null; when = java.lang.SystemJ.currentTimeMillis(); }
public InvocationEvent(Object source, java.lang.Runnable runnable, Object notifier, bool catchExceptions) : this(source, INVOCATION_DEFAULT, runnable, notifier, catchExceptions) { }
public InvocationEvent(Object source, java.lang.Runnable runnable) : this(source, runnable, null, false) { }