Java???WebSocket??Tomcat???
???????????? ???????[ 2016/2/18 10:15:35 ] ??????????????????? ???????
????Java Web??????
1 package me.gacl.websocket; 2 3 import java.io.IOException; 4 import java.util.concurrent.CopyOnWriteArraySet; 5 6 import javax.websocket.*; 7 import javax.websocket.server.ServerEndpoint; 8 9 /** 10 * @ServerEndpoint ???????????ε?????????????????????????????websocket????????? 11 * ??????????????????????????????URL???????????????????URL???????WebSocket???????? 12 */ 13 @ServerEndpoint("/websocket") 14 public class WebSocketTest { 15 //?????????????????????????????????e??????????????? 16 private static int onlineCount = 0; 17 18 //concurrent?????????Set?????????????????????MyWebSocket????????????????????????????????????Map??????????Key??????????? 19 private static CopyOnWriteArraySet<WebSocketTest> webSocketSet = new CopyOnWriteArraySet<WebSocketTest>(); 20 21 //?????????????????????????????????????????? 22 private Session session; 23 24 /** 25 * ?????????????????? 26 * @param session ??????????session??????????????????????????????????????????? 27 */ 28 @OnOpen 29 public void onOpen(Session session){ 30 this.session = session; 31 webSocketSet.add(this); //????set?? 32 addOnlineCount(); //????????1 33 System.out.println("???????????????????????" + getOnlineCount()); 34 } 35 36 /** 37 * ????????????? 38 */ 39 @OnClose 40 public void onClose(){ 41 webSocketSet.remove(this); //??set????? 42 subOnlineCount(); //????????1 43 System.out.println("??????????????????????" + getOnlineCount()); 44 } 45 46 /** 47 * ???????????????????? 48 * @param message ???????????????? 49 * @param session ???????? 50 */ 51 @OnMessage 52 public void onMessage(String message?? Session session) { 53 System.out.println("????????????:" + message); 54 //?????? 55 for(WebSocketTest item: webSocketSet){ 56 try { 57 item.sendMessage(message); 58 } catch (IOException e) { 59 e.printStackTrace(); 60 continue; 61 } 62 } 63 } 64 65 /** 66 * ????????????? 67 * @param session 68 * @param error 69 */ 70 @OnError 71 public void onError(Session session?? Throwable error){ 72 System.out.println("????????"); 73 error.printStackTrace(); 74 } 75 76 /** 77 * ????????????漸????????????????????????????????????????? 78 * @param message 79 * @throws IOException 80 */ 81 public void sendMessage(String message) throws IOException{ 82 this.session.getBasicRemote().sendText(message); 83 //this.session.getAsyncRemote().sendText(message); 84 } 85 86 public static synchronized int getOnlineCount() { 87 return onlineCount; 88 } 89 90 public static synchronized void addOnlineCount() { 91 WebSocketTest.onlineCount++; 92 } 93 94 public static synchronized void subOnlineCount() { 95 WebSocketTest.onlineCount--; 96 } 97 }
????2.2.????Ч??
????????Google?????????????????ж????????????????Ч??????:
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????