Using the Raw Native Interface |
![]() Previous |
![]() Introduction |
![]() Next |
Native methods marked as being synchronized don't automatically lock\unlock the object so you must do any necessary synchronization on the native side. ObjectMonitorEnter() takes an object monitor, ObjectMonitorExit() leaves it, ObjectMonitorNotify() is analogous to Object.notify() and ObjectMonitorNotifyAll() is analogous to Object.notifyAll(). For example, a typical synchronized method will look like
long cdecl Some_Java_SynchronizedMethod(struct HSomeJava *phThisUnsafe) { // Normal GC protection stuff. HSomeJava *phThisSafe; GCFrame gcf; GCFramePush(&gcf, &phThisSafe, sizeof(phThisSafe)); phThisSafe = phThisUnsafe; ObjectMonitorEnter(phThisSafe); // Code here executes synchronised on this object. ObjectMonitorExit(phThisSafe); GCFramePop(&gcf); }