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