diff --git a/src/macosx/native/sun/awt/LWCToolkit.m b/src/macosx/native/sun/awt/LWCToolkit.m index 630c0eed9748bb40ac01bf83238aa097623b7e07..d619655e4d998f6b04f31525140146d08c448058 100644 --- a/src/macosx/native/sun/awt/LWCToolkit.m +++ b/src/macosx/native/sun/awt/LWCToolkit.m @@ -188,14 +188,15 @@ JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_initIDs (JNIEnv *env, jclass klass) { // set thread names - dispatch_async(dispatch_get_main_queue(), ^(void){ - [[NSThread currentThread] setName:@"AppKit Thread"]; - - JNIEnv *env = [ThreadUtilities getJNIEnv]; - static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); - static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); - JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); - }); + if (![ThreadUtilities isAWTEmbedded]) { + dispatch_async(dispatch_get_main_queue(), ^(void){ + [[NSThread currentThread] setName:@"AppKit Thread"]; + JNIEnv *env = [ThreadUtilities getJNIEnv]; + static JNF_CLASS_CACHE(jc_LWCToolkit, "sun/lwawt/macosx/LWCToolkit"); + static JNF_STATIC_MEMBER_CACHE(jsm_installToolkitThreadInJava, jc_LWCToolkit, "installToolkitThreadInJava", "()V"); + JNFCallStaticVoidMethod(env, jsm_installToolkitThreadInJava); + }); + } gNumberOfButtons = sun_lwawt_macosx_LWCToolkit_BUTTONS; diff --git a/src/macosx/native/sun/awt/awt.m b/src/macosx/native/sun/awt/awt.m index 16262af9715e99c09226536ae41c50d1cdd5e1b0..293a6c05c03a495874c7d0dbffd6942f9b1f02cd 100644 --- a/src/macosx/native/sun/awt/awt.m +++ b/src/macosx/native/sun/awt/awt.m @@ -363,6 +363,7 @@ AWT_ASSERT_APPKIT_THREAD; // AppKit Application. NSApplication *app = [NSApplicationAWT sharedApplication]; isEmbedded = ![NSApp isKindOfClass:[NSApplicationAWT class]]; + [ThreadUtilities setAWTEmbedded:isEmbedded]; if (!isEmbedded) { // Install run loop observers and set the AppKit Java thread name diff --git a/src/macosx/native/sun/osxapp/ThreadUtilities.h b/src/macosx/native/sun/osxapp/ThreadUtilities.h index 2cd41aa0c894ace4876ca6349d7e6cad26dfc4b8..6a469cd4cd8a778f8f70db9b259be277e3720aed 100644 --- a/src/macosx/native/sun/osxapp/ThreadUtilities.h +++ b/src/macosx/native/sun/osxapp/ThreadUtilities.h @@ -129,6 +129,8 @@ __attribute__((visibility("default"))) + (JNIEnv*)getJNIEnvUncached; + (void)detachCurrentThread; + (void)setAppkitThreadGroup:(jobject)group; ++ (void)setAWTEmbedded:(BOOL)embedded; ++ (BOOL)isAWTEmbedded; //Wrappers for the corresponding JNFRunLoop methods with a check for main thread + (void)performOnMainThreadWaiting:(BOOL)wait block:(void (^)())block; diff --git a/src/macosx/native/sun/osxapp/ThreadUtilities.m b/src/macosx/native/sun/osxapp/ThreadUtilities.m index b7d3b3f55248434754c737037d9c69f018cd8ca5..7458431010b7fc11dea9015e11ac06a6c99aa1cd 100644 --- a/src/macosx/native/sun/osxapp/ThreadUtilities.m +++ b/src/macosx/native/sun/osxapp/ThreadUtilities.m @@ -34,6 +34,7 @@ JavaVM *jvm = NULL; static JNIEnv *appKitEnv = NULL; static jobject appkitThreadGroup = NULL; +static BOOL awtEmbedded = NO; inline void attachCurrentThread(void** env) { if ([NSThread isMainThread]) { @@ -87,6 +88,14 @@ AWT_ASSERT_APPKIT_THREAD; } } ++ (void)setAWTEmbedded:(BOOL)embedded { + awtEmbedded = embedded; +} + ++ (BOOL)isAWTEmbedded { + return awtEmbedded; +} + @end