windows 7 待命記憶體 佔了超過2G的 RAM的問題,
但是卻沒法關掉這個鬼待命...
後來上網找了很多方法,
僅能減少,無法關閉....
以下是減少待命吃的記憶體大小方法
- 到 電源管理,關閉 系統休眠、睡眠。
- 若是使用內建顯示卡,請至 BIOS裡,設定 顯示卡記憶體大小,
不要使用 MAX or AUTO 這類的設定。 - 降低 螢幕解析度
以上。
import java.io.IOException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.ClientEndpoint;
import javax.websocket.CloseReason;
import javax.websocket.ContainerProvider;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
@ClientEndpoint
public class WSClient {
private static final Logger logger = Logger.getLogger("WSClient");
private static WSClient instance = null;
public static WebSocketContainer container = null;//
public static Session session = null;
public static String wsServerURL = "ws://localhost:8080/ws";
// flag for connect of websocket
public static boolean isConnect = false;
public static WSClient createInstance(String wsServerURL) {
logger.log(Level.INFO, "createInstance");
WSClient.wsServerURL = wsServerURL;
instance = new WSClient();
instance.autoConnection(2);
return instance;
}
public static void destroyInstance() {
terminateToServer();
instance = null;
}
public static WSClient getInstance() {
return instance;
}
public boolean connectToServer() {
try {
// Tyrus is plugged via ServiceLoader API. See notes above
container = ContainerProvider.getWebSocketContainer();
// WS1 is the context-root of my web.app
// ratesrv is the path given in the ServerEndPoint annotation on
// server implementation
session = container.connectToServer(WSClient.class, URI.create(wsServerURL));
isConnect = true;
} catch (Exception e) {
e.printStackTrace();
isConnect = false;
}
return isConnect;
}
public static void terminateToServer() {
if (session != null) {
try {
session.close();
} catch (Exception e) {
e.printStackTrace();
}
session = null;
container = null;
isConnect = false;
}
}
public synchronized void autoConnection(int retryCountLimit) {
// 沒連線的情況下才進去
if (!isConnect) {
int retryCount = 0;
do {
retryCount++;
connectToServer();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
} while (!isConnect && retryCount < retryCountLimit);
}
}
public void send(String msg) {
autoConnection(2);
if (isConnect) {
try {
session.getBasicRemote().sendText(msg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@OnOpen
public void onOpen(Session session) {
// same as above
logger.log(Level.INFO, "onOpen" + session.getId());
isConnect = true;
}
@OnMessage
public void onMessage(String message, Session session) {
// the new USD rate arrives from the websocket server side.
logger.log(Level.INFO, "onMessage: " + message);
}
@OnClose
public void onClose(Session session, CloseReason closeReason) {
logger.log(Level.INFO, "onClose: " + session.getId());
isConnect = false;
}
}
Endpoint class:package websocketTest;
import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/dukeetf")
public class ETFEndpoint {
private static final Logger logger = Logger.getLogger("ETFEndpoint");
static Queue<Session> queue = new ConcurrentLinkedQueue<>();
@OnMessage
public void onMessage(Session session, String msg) {
try {
session.getBasicRemote().sendText(msg);
} catch (IOException e) {
}
}
/* PriceVolumeBean calls this method to send updates */
public static void send(double price, int volume) {
String msg = String.format("%.2f, %d", price, volume);
try {
/* Send updates to all open WebSocket sessions */
for (Session session : queue) {
session.getBasicRemote().sendText(msg);
logger.log(Level.INFO, "Sent: {0}", msg);
}
} catch (IOException e) {
logger.log(Level.INFO, e.toString());
}
}
@OnOpen
public void openConnection(Session session) {
/* Register this connection in the queue */
queue.add(session);
logger.log(Level.INFO, "Connection opened.");
}
@OnClose
public void closedConnection(Session session) {
/* Remove this connection from the queue */
queue.remove(session);
logger.log(Level.INFO, "Connection closed.");
}
@OnError
public void error(Session session, Throwable t) {
/* Remove this connection from the queue */
queue.remove(session);
logger.log(Level.INFO, t.toString());
logger.log(Level.INFO, "Connection error.");
}
}