Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » best way to distinguish main ui thread and background threads(RAP 2.3.2)
best way to distinguish main ui thread and background threads [message #1732881] Sat, 21 May 2016 23:50 Go to next message
Tass Burrfoot is currently offline Tass BurrfootFriend
Messages: 19
Registered: April 2015
Junior Member
Hello

I have a method that should be accessed only by background threads. I want to throw AssertionError if the method is accessed by the main UI thread.

I tried
if (Display.findDisplay(Thread.currentThread())!=null)
but this line throws illegal state exception itself.

If I print thread name directly by
Thread.currentThread().getName()
it prints: UIThread [...]

Is there any way to get the main thread name "UIThread [...]" from RAP api? For now I store the main thread name to a static variable when the application starts up. That's not handy. What is the best way to check whether the executing thread is main thread or background thread in RAP? Thanks
Re: best way to distinguish main ui thread and background threads [message #1732888 is a reply to message #1732881] Sun, 22 May 2016 06:44 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Tass,

Try org.eclipse.swt.widgets.Display.getCurrent().

On 22.05.2016 01:50, Tass Burrfoot wrote:
> Hello
>
> I have a method that should be accessed only by background threads. I
> want to throw AssertionError if the method is accessed by the main UI
> thread.
>
> I tried
> if (Display.findDisplay(Thread.currentThread())!=null)
> but this line throws illegal state exception itself.
>
> If I print thread name directly by
> Thread.currentThread().getName()
> it prints: UIThread [...]
>
> Is there any way to get the main thread name "UIThread [...]" from RAP
> api? For now I store the main thread name to a static variable when
> the application starts up. That's not handy. What is the best way to
> check whether the executing thread is main thread or background thread
> in RAP? Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Questions regarding context menus
Next Topic: Correct usage of ProgressMonitorDialog with modal dialogs
Goto Forum:
  


Current Time: Tue Mar 19 04:04:28 GMT 2024

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

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

Back to the top