2013-10-27 44 views
0

请帮我解决问题。
我想通过队列将数据从gui线程发送到另一个线程。
但我遇到了问题。当另一个线程正在使用队列时,GUI线程将一个对象添加到队列中,Gui线程将被阻塞一些毫秒。所以GUI不光滑。
我的班级:这是多线程Java中的队列,无阻塞

public enum AresManager { 
MANAGER; 
Queue<AresAction> actionsQueue = new LinkedList<AresAction>(); 

public synchronized void sendAction(Context context, AresAction action) { 
    actionsQueue.add(action); 
    Intent intent = new Intent(context, AresServiceSingleHandler.class); 
    context.startService(intent); 
} 

public synchronized AresAction getActionFromQueue() { 
    AresAction action = actionsQueue.poll(); 
    AresLog.v("[Actions Queue] size = " + actionsQueue.size() 
      + " (always should be 0)"); 
    return action; 
} 

}

回答