Search API利用中にConcurrentModificationExceptionがでていた問題を修正
@@ -105,12 +105,15 @@ | ||
105 | 105 | */ |
106 | 106 | @Override |
107 | 107 | public void onStatus(Status status) { |
108 | - for(String word : listeners.keySet()) { | |
109 | - if( status.getText().contains( word.toString() ) ) { | |
110 | - TweetStreamingListener listener = listeners.get(word); | |
111 | - listener.update(status); | |
112 | - //最終更新id | |
113 | - lastUpdate.put(word, status.getId()); | |
108 | + Set<String> keys = listeners.keySet(); | |
109 | + synchronized (listeners) { | |
110 | + for(String word : keys) { | |
111 | + if( status.getText().contains( word.toString() ) ) { | |
112 | + TweetStreamingListener listener = listeners.get(word); | |
113 | + listener.update(status); | |
114 | + //最終更新id | |
115 | + lastUpdate.put(word, status.getId()); | |
116 | + } | |
114 | 117 | } |
115 | 118 | } |
116 | 119 | } |
@@ -143,13 +146,12 @@ | ||
143 | 146 | } catch (TwitterException e) { |
144 | 147 | e.printStackTrace(); |
145 | 148 | } |
146 | - for(;;) { | |
149 | + for(; statusStream != null; ) { | |
147 | 150 | try { |
148 | - if( statusStream != null ) { | |
149 | - statusStream.next(this); | |
150 | - } | |
151 | - } catch (TwitterException e) { | |
151 | + statusStream.next(this); | |
152 | + }catch(Exception e) { | |
152 | 153 | e.printStackTrace(); |
154 | + break; | |
153 | 155 | } |
154 | 156 | } |
155 | 157 | } |