1
我試圖通過ScheduledExecutorService
在Android中實現生產者 - 消費者模式。所以,我創建了一個生產者工作線程,用於從網站和消費者線程中加載數據以過濾這些數據。這裏是我的問題演示代碼片段:如何在Android的ScheduledExecutorService產生的兩個線程之間傳遞數據?
public void RunPeriodicBackgroundTasks() {
private final ScheduledExecutorService backgroundTaskExecutor_ = Executors.newScheduledThreadPool(2);
backgroundTaskExecutor_.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
LinkedHashMap<String, Object> result_ = new LinkedHashMap<String, Object>(lowLevelNetworkOperation_.executeServerCommand(DASHBOARD_INBOX_SENT_COMMAND, params));
}
},1 ,3, SECONDS);
//AND NOW I CREATE ANOTHER THREAD for the second task
backgroundTaskExecutor_.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
//HERE I WANT To USE result_
}
}, 1,3, SECONDS);
}