Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is a background thread and why do I need one?

background thread
0
Posted

What is a background thread and why do I need one?

0

As with most user interface (UI) toolkits, Swing is single threaded. That means there is one and only one thread that should create or alter the state of UI components, and that is the AWT Event Dispatch Thread (also known as the EDT or the “event thread”). It processes things like key and mouse events and calls components to respond to them. This also means that code that responds to a key or mouse event, or some call triggered by one, should run very quickly, because the user can by typing or clicking, but the entire application is blocked from responding to more events until your code exits. So sometimes you will want to move expensive or slow work onto a background thread. A background thread is any thread that is not the event thread. If you are running on some other thread, but need to modify some component, a simple way to do this is EventQueue.invokeLater(new Runnable() { public void run() { //this code can modify components } }); Note that the caveat about Swing includes creat

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123