Sun Microsystems 2 Wireless Office Headset User Manual


 
12 Multitasking Guide May 2007
public static synchronized setPower(int power) {
if (owner != Thread.currentThread()) {
throw new IllegalStateException();
}
n_setPower(power);
}
public static synchronized setTime(int nsecs) {
if (owner != Thread.currentThread()) {
throw new IllegalStateException();
}
n_setTime(nsecs);
}
public static synchronized int cook() {
if (owner != Thread.currentThread()) {
throw new IllegalStateException();
}
return n_cook();
}
private static native void init();
private static native void n_setTime(int nsecs);
private static native void n_setPower(int power);
private static native int n_cook();
private Microwave() { } /* prevent instance creation */
}
Expected usage of this new API from Java platform programs is shown in
CODE EXAMPLE 2-5.
CODE EXAMPLE 2-5 Using the Locking Mechanism
Microwave.lock();
try {
Microwave.setTime(180);
Microwave.setPower(100);
if (Microwave.cook() == ...) {
...
} else {
...
}
} finally {
Microwave.unlock();
}