Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » how can i know if i'm running in a top level thread?(preventing a crash...)
icon5.gif  how can i know if i'm running in a top level thread? [message #640186] Fri, 19 November 2010 09:12 Go to next message
Eclipse UserFriend
i have a method which maybe called inside a the main thread or inside another one,

how do i know if i'm running in side the main thread? (it's using jacom, and i need to know if i should run in mta or sta)
Re: how can i know if i'm running in a top level thread? [message #640272 is a reply to message #640186] Fri, 19 November 2010 15:32 Go to previous messageGo to next message
Eclipse UserFriend
I tested it. You can check with this:
if (Thread.currentThread().getName().equals("main")) {
    // do something
}

Strangely, == doesn't work, but .equals() does. == probably compares the object, not the contents of the string.

[Updated on: Fri, 19 November 2010 15:33] by Moderator

Re: how can i know if i'm running in a top level thread? [message #640323 is a reply to message #640272] Sat, 20 November 2010 10:45 Go to previous messageGo to next message
Eclipse UserFriend
really? tha sounds really faglie, i mean there's nothing to stop oracle from changing the name, between versions (hell they changed the jvm name, in jdk 6_21 and caused problems for eclipse)
Re: how can i know if i'm running in a top level thread? [message #640349 is a reply to message #640186] Sat, 20 November 2010 20:30 Go to previous messageGo to next message
Eclipse UserFriend
Well, I suppose you could store the name of the thread in a global variable when the program first starts in main(), because you know for sure you're in the main thread then. Then you can compare to the stored value later.
Re: how can i know if i'm running in a top level thread? [message #640368 is a reply to message #640349] Sun, 21 November 2010 00:37 Go to previous messageGo to next message
Eclipse UserFriend
bu this is eclipse we are talking about, don't have access to main
Re: how can i know if i'm running in a top level thread? [message #640421 is a reply to message #640186] Sun, 21 November 2010 17:37 Go to previous messageGo to next message
Eclipse UserFriend
Oh, so this isn't just a Java application, this is some Eclipse thing? Then I don't know. Just use "main" and fix it when it breaks Smile (unless there's a better solution that I don't know of).
Re: how can i know if i'm running in a top level thread? [message #640431 is a reply to message #640186] Sun, 21 November 2010 23:32 Go to previous messageGo to next message
Eclipse UserFriend
if this thing breaks, there's a good chance it would take eclipse down with it. so i can't risk it:)
Re: how can i know if i'm running in a top level thread? [message #640765 is a reply to message #640186] Tue, 23 November 2010 00:16 Go to previous message
Eclipse UserFriend
Er, oh. Good point Rolling Eyes
Previous Topic:[solved] drawing to a GC through SWT and native code
Next Topic:Default size of a Composite
Goto Forum:
  


Current Time: Thu Jul 03 05:57:35 EDT 2025

Powered by FUDForum. Page generated in 0.54673 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top