The keyword here is "decoupling" and failing to do it correctly is a common beginner issue wich lead to your mentioned "locking up of the whole application".
It comes down to how GUIs in
Java work (keyword "EDT" - Event Dispatch
Thread) and that beginners often not correctly understand why they need to run their code in a different thread than where the event is triggert.
Just by experience I guess your code looks a bit like this: You have some listener wich reacts to some event triggert by some button or alike and then, as the query takes time, your application becomes unresponsive. That's because you most likely locking up the EDT wich needs to always run clean by itself to keep the UI responsive. Care must also be taken when you want to update your GUI after your task has finished: You have to re-inject anything modifying the GUI back into the EDT. In Swing this is done with SwingUtilities.invokeLater(). FX should have something similar.