|[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]|
Fettig Thomas wrote:
Does JNI still work with Carbon on this basic level (FileManager, Resource Manager). Btw i have to read and write resource Data. Or should i forget it (and not go to work the next few days .. ;-)
We have JNI code that uses many Carbon APIs without problem (e.g. SoundManager). What seems to be the big problem are GUI elements -- do not use Carbon GUI components. In many ways the Carbon event loop *can* coexist with the Cocoa JVM (1.4+ JVMs are Cocoa based, 1.3* are Carbon based), for example we use the Carbon Hot Keys API with success from a 1.4.2 JVM. There *are* threading issues to worry about with the Carbon APIs. Earlier (1.3*) JVMs had a "Carbon Lock" that JNI calls needed to acquire before calling Carbon APIs. That is gone now. Also, many OS X APIs are not thread-safe, and callers must ensure only one thread at a time calls them (in some cases only one thread of a process may ever call the API, and in some cases only the main AppKit thread may call the API). Check the API documentation for thread safety notices -- if there isn't one, then the API is not thread safe. Apple's recommendation is to only call such APIs from the main AppKit thread (which is different from the main Java thread -- the AppKit thread is only visible to Java when a native callback attaches to the JVM via JNI and calls up to Java). The only way for 1.4 JNI code to call native routines on the AppKit thread is via an NSObject method: performSelectorOnMainThread (and only via Objective-C). If you call such APIs from any thread, your code may work fine 99.999% of the time, but crash and burn if you get unlucky and call it concurrently with native code on the AppKit thread (most likely vs. the JVM itself).
If you just need to read and write resource forks, the easiest route is to use the MacBinaryToolkit (mentioned earlier), or use the "named fork" syntax (see the archives: http://lists.apple.com/archives/java-dev/2004/Oct/msg00668.html http://lists.apple.com/archives/java-dev/2005/Aug/msg00107.html) I've not tried calling the ResourceManager from JNI, I'd guess it would be sufficient to ensure that only one of the Java threads is calling it (using a conventional Java monitor), I doubt that the Cocoa JVMs use the ResourceManager at all. However, this is just a guess, I've been wrong before. _______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
Visit the Apple Store online or at retail locations.
Copyright © 2011 Apple Inc. All rights reserved.