java 内存 检测_Java内存使用情况检测代码
時(shí)間:2019-07-14
概述:內(nèi)存檢測(cè)
Java實(shí)現(xiàn)的內(nèi)存檢測(cè)代碼,可檢測(cè)出總內(nèi)存空間大小、剩余內(nèi)存空間大小、已使用內(nèi)存多少,若看懂了代碼,自己擴(kuò)展一下還是不錯(cuò)的。
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Memory extends MIDlet implements CommandListener {
private Display display;
private Form props;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
public Memory() {
display = Display.getDisplay(this);
}
public void startApp() {
props = new Form("Runtime Information");
// 總內(nèi)存空間大小
long total = Runtime.getRuntime().totalMemory();
// 剩余內(nèi)存空間大小
long free = Runtime.getRuntime().freeMemory();
props.append("total memory:" + total + "\n");
props.append("free memory:" + free + "\n");
props.append("used memory:" + (total-free) +"\n");
props.addCommand(exitCommand);
props.setCommandListener(this);
display.setCurrent(props);
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
public void destroyApp(boolean unconditional) {
}
public void pauseApp() {
display.setCurrent(null);
props = null;
}
}
總結(jié)
以上是生活随笔為你收集整理的java 内存 检测_Java内存使用情况检测代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 对app请求的参数和响应进行rsa加密和
- 下一篇: Java源码阅读--任重而道远(lang