[英]Thread pool for async tasks?
我正在使用JFace編寫一個簡單的文件瀏覽器應用程序。 應用程序的邏輯可以簡化為:
因此,在我的觀點中,至少涉及2個線程:a)UI線程和b)提取文件夾內容的后台線程。
真正困擾我的是這兩個線程之間是如何通信的,我是否必須“發明輪子”? 更加具體:
我通常會做的是這樣的:
// On double-click, start a new thread
new Thread(new Runnable()
{
@Override
public void run()
{
// Get your new data in this thread
final MyFancyDataObject data = SomeOtherClass.goAndGetMyData();
// Update the GUI, this is the safe way to do it from a non-gui-thread
Display.getCurrent().asyncExec(new Runnable()
{
public void run()
{
GuiClass.updateContent(data);
}
});
}
}).start();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.