Difference between display. getdefault () and display. getcurrent ()

Source: Internet
Author: User

Display. getdefault (): This method returns the display instance in the user GUI thread, regardless of whether the current thread is a user GUI thread,

If this instance does not exist, a display instance in the GUI thread is created by default.

 

Java code

/**

* Returns the default display. One is created (making the thread that

* Invokes this method its user-interface thread) if it did not already

* Exist.

*

* @ Return the default display

*/

Public static display getdefault ()

{

Synchronized (device. Class)

{

If (default = NULL)

Default = New Display ();

Return default;

}

}

 

 

 

Display. getcurrent (): return the display instance in the current thread. If this is a graphical interface thread, the instance is not empty. If the current thread is not a graphical interface thread, the instance is empty.

 

You can determine whether the current thread is an interface thread based on whether the display instance returned by display. getcurrent () is null. If it is not null, it is an interface thread; otherwise, it is a background thread.

 

 

Java code

/**

* Returns the display which the currently running thread is

* User-interface thread for, or null if the currently running thread is not

* A user-interface thread for any display.

*

* @ Return the current display

*/

Public static display getcurrent ()

{

Return finddisplay (thread. currentthread ());

}

In the subsequent articles, we will particularly describe the interface thread and background thread in SWT.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.