Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 14:12 Go to next message
elhanan Maayan is currently offline elhanan MaayanFriend
Messages: 131
Registered: November 2009
Senior Member
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 20:32 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
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.


Premature developer

[Updated on: Fri, 19 November 2010 20:33]

Report message to a 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 15:45 Go to previous messageGo to next message
elhanan Maayan is currently offline elhanan MaayanFriend
Messages: 131
Registered: November 2009
Senior Member
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] Sun, 21 November 2010 01:30 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
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.

Premature developer
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 05:37 Go to previous messageGo to next message
elhanan Maayan is currently offline elhanan MaayanFriend
Messages: 131
Registered: November 2009
Senior Member
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 22:37 Go to previous messageGo to next message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
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).

Premature developer
Re: how can i know if i'm running in a top level thread? [message #640431 is a reply to message #640186] Mon, 22 November 2010 04:32 Go to previous messageGo to next message
elhanan Maayan is currently offline elhanan MaayanFriend
Messages: 131
Registered: November 2009
Senior Member
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 05:16 Go to previous message
Jonah Bron is currently offline Jonah BronFriend
Messages: 32
Registered: October 2010
Location: California
Member
Er, oh. Good point Rolling Eyes

Premature developer
Previous Topic:mouse wheel sends extra scroll event
Next Topic:Mouse Event Zones On Canvas
Goto Forum:
  


Current Time: Tue Oct 24 11:37:37 GMT 2017

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

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