Commit d5fd0b77be2e94e861a02d218865f17c47dbd68f
1 parent
fda49142
去掉synchronized ,改成多例
Showing
1 changed file
with
3 additions
and
2 deletions
src/main/java/com/bsth/websocket/handler/RealControlSocketHandler.java
| ... | ... | @@ -6,6 +6,7 @@ import java.util.Set; |
| 6 | 6 | |
| 7 | 7 | import org.slf4j.Logger; |
| 8 | 8 | import org.slf4j.LoggerFactory; |
| 9 | +import org.springframework.context.annotation.Scope; | |
| 9 | 10 | import org.springframework.stereotype.Component; |
| 10 | 11 | import org.springframework.web.socket.CloseStatus; |
| 11 | 12 | import org.springframework.web.socket.TextMessage; |
| ... | ... | @@ -17,10 +18,10 @@ import com.bsth.common.Constants; |
| 17 | 18 | import com.bsth.data.BasicData; |
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | - * 注意:在sendMsg时,多线程状态下有几率出现连接状态脏读,建议 synchronized | |
| 21 | 21 | * @author PanZhao |
| 22 | 22 | */ |
| 23 | 23 | @Component |
| 24 | +@Scope("prototype") | |
| 24 | 25 | public class RealControlSocketHandler implements WebSocketHandler { |
| 25 | 26 | |
| 26 | 27 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| ... | ... | @@ -107,7 +108,7 @@ public class RealControlSocketHandler implements WebSocketHandler { |
| 107 | 108 | * @param userId |
| 108 | 109 | * @param message |
| 109 | 110 | */ |
| 110 | - public synchronized void sendMessageToLine(String lineCode, String msg) { | |
| 111 | + public void sendMessageToLine(String lineCode, String msg) { | |
| 111 | 112 | Set<String> uids = BasicData.lineCode2SocketUserMap.get(lineCode); |
| 112 | 113 | if(null == uids || uids.size() == 0) |
| 113 | 114 | return; | ... | ... |