Project

General

Profile

« Previous | Next » 

Revision 9ef86c9f

Added by Leszek Koltunski about 3 years ago

On second thought, come back to Vector. The problem: before we had the potentially blocking function 'effectFinished' inside our synchronized block.

View differences:

src/main/java/org/distorted/library/message/EffectMessageSender.java
21 21

  
22 22
import org.distorted.library.effect.Effect;
23 23

  
24
import java.util.ArrayList;
24
import java.util.Vector;
25 25

  
26 26
///////////////////////////////////////////////////////////////////////////////////////////////////
27 27
/**
......
43 43
      }
44 44
    }
45 45

  
46
  private static final Object mArrayLock   = new Object();
47 46
  private static final Object mLock        = new Object();
48
  private static ArrayList<Message> mList  = null;
47
  private static Vector<Message> mList     = null;
49 48
  private static EffectMessageSender mThis = null;
50 49
  private static volatile boolean mNotify  = false;
51 50

  
......
71 70

  
72 71
      if( mThis==null )
73 72
        {
74
        mList = new ArrayList<>();
73
        mList = new Vector<>();
75 74
        mThis = new EffectMessageSender();
76 75
        mThis.start();
77 76
        }
......
103 102
     
104 103
    while(mThis!=null)
105 104
      {
106
      synchronized(mArrayLock)
105
      while( mList.size()>0 )
107 106
        {
108
        int size = mList.size();
109

  
110
        for(int i=0; i<size; i++)
111
          {
112
          tmp = mList.remove(0);
113
          tmp.mListener.effectFinished(tmp.mEffectID);
114
          }
107
        tmp = mList.remove(0);
108
        tmp.mListener.effectFinished(tmp.mEffectID);
115 109
        }
116 110

  
117 111
      synchronized(mLock)
......
138 132
      {
139 133
      long id = effect.getID();
140 134

  
141
      synchronized(mArrayLock)
135
      for(int i=0; i<numListeners; i++)
142 136
        {
143
        for(int i=0; i<numListeners; i++)
144
          {
145
          EffectListener listener = effect.removeFirstListener();
146
          Message msg = new Message(listener,id);
147
          mList.add(msg);
148
          }
137
        EffectListener listener = effect.removeFirstListener();
138
        Message msg = new Message(listener,id);
139
        mList.add(msg);
149 140
        }
150 141

  
151 142
      synchronized(mLock)
......
171 162
      {
172 163
      if( mThis==null )
173 164
        {
174
        if( mList==null ) mList = new ArrayList<>();
165
        if( mList==null ) mList = new Vector<>();
175 166
        mThis = new EffectMessageSender();
176 167
        mThis.start();
177 168
        }

Also available in: Unified diff