< prev index next >

src/java.corba/share/classes/com/sun/corba/se/impl/orbutil/concurrent/Sync.java

Print this page

        

*** 179,193 **** * } * catch (InterruptedException ex) { return; } * } * } * } ! *</pre> * <p> * Here is an even fancier version, that uses lock re-ordering * upon conflict: ! * <pre> * class Cell { * long value; * Sync lock = ...; * private static boolean trySwap(Cell a, Cell b) { * a.lock.acquire(); --- 179,193 ---- * } * catch (InterruptedException ex) { return; } * } * } * } ! * </pre> * <p> * Here is an even fancier version, that uses lock re-ordering * upon conflict: ! * <pre>{@code * class Cell { * long value; * Sync lock = ...; * private static boolean trySwap(Cell a, Cell b) { * a.lock.acquire();
*** 212,223 **** * !tryswap(other, this)) * Thread.sleep(1); * } * catch (InterruptedException ex) { return; } * } ! *} ! *</pre> * <p> * Interruptions are in general handled as early as possible. * Normally, InterruptionExceptions are thrown * in acquire and attempt(msec) if interruption * is detected upon entry to the method, as well as in any --- 212,223 ---- * !tryswap(other, this)) * Thread.sleep(1); * } * catch (InterruptedException ex) { return; } * } ! * } ! * }</pre> * <p> * Interruptions are in general handled as early as possible. * Normally, InterruptionExceptions are thrown * in acquire and attempt(msec) if interruption * is detected upon entry to the method, as well as in any
*** 246,256 **** * <p> * Syncs may also be used in spinlock constructions. Although * it is normally best to just use acquire(), various forms * of busy waits can be implemented. For a simple example * (but one that would probably never be preferable to using acquire()): ! * <pre> * class X { * Sync lock = ... * void spinUntilAcquired() throws InterruptedException { * // Two phase. * // First spin without pausing. --- 246,256 ---- * <p> * Syncs may also be used in spinlock constructions. Although * it is normally best to just use acquire(), various forms * of busy waits can be implemented. For a simple example * (but one that would probably never be preferable to using acquire()): ! * <pre>{@code * class X { * Sync lock = ... * void spinUntilAcquired() throws InterruptedException { * // Two phase. * // First spin without pausing.
*** 267,285 **** * else * waitTime = waitTime * 3 / 2 + 1; // increase 50% * } * } * } ! * </pre> * <p> * In addition pure synchronization control, Syncs * may be useful in any context requiring before/after methods. * For example, you can use an ObservableSync * (perhaps as part of a LayeredSync) in order to obtain callbacks * before and after each method invocation for a given class. * ! * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] **/ public interface Sync { --- 267,285 ---- * else * waitTime = waitTime * 3 / 2 + 1; // increase 50% * } * } * } ! * }</pre> * <p> * In addition pure synchronization control, Syncs * may be useful in any context requiring before/after methods. * For example, you can use an ObservableSync * (perhaps as part of a LayeredSync) in order to obtain callbacks * before and after each method invocation for a given class. * ! * [<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] **/ public interface Sync {
< prev index next >