Ejemplo n.º 1
0
 public static String getMemoryInformation() {
   Runtime rt = Runtime.getRuntime();
   DecimalFormat df = new DecimalFormat("###,###,###,###");
   return "used = "
       + df.format(rt.totalMemory() - rt.freeMemory())
       + " free = "
       + rt.freeMemory()
       + " total = "
       + rt.totalMemory()
       + " max = "
       + rt.maxMemory();
 }
Ejemplo n.º 2
0
	public static void main(String[] args) throws Exception{
		//free和use和total均为KB 
		long free=0; 
		long use=0; 
		long total=0;  
		int kb=1024;

		Runtime rt=Runtime.getRuntime();
		total=rt.totalMemory();
		free=rt.freeMemory();
		use=total-free;
		
		System.out.println("系统内存已用的空间为:"+use/kb+" MB");
		System.out.println("系统内存的空闲空间为:"+free/kb+" MB");
		System.out.println("系统总内存空间为:"+total/kb+" MB");   

		OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
		
		long physicalFree=osmxb.getFreePhysicalMemorySize()/kb;
		long physicalTotal=osmxb.getTotalPhysicalMemorySize()/kb;
		long physicalUse=physicalTotal-physicalFree;
		String os=System.getProperty("os.name");
		System.out.println("操作系统的版本:"+os);
		System.out.println("系统物理内存已用的空间为:"+physicalFree+" MB");
		System.out.println("系统物理内存的空闲空间为:"+physicalUse+" MB");
		System.out.println("总物理内存:"+physicalTotal+" MB");

		// 获得线程总数 
        	ThreadGroup parentThread;
        	for (parentThread = Thread.currentThread().getThreadGroup(); parentThread.getParent() != null; parentThread = parentThread.getParent())
			;
		int totalThread = parentThread.activeCount();

		System.out.println("获得线程总数:"+totalThread);
	}
Ejemplo n.º 3
0
 private void handleException(Realm realm, OutOfMemoryError e) {
   // Try to recover after OOM.
   Runtime rt = Runtime.getRuntime();
   long beforeGc = rt.freeMemory();
   rt.gc();
   long afterGc = rt.freeMemory();
   if (afterGc > beforeGc && (afterGc - beforeGc) < 50_000_000) {
     // Calling gc() cleared less than 50MB, assume unrecoverable OOM and rethrow error.
     throw e;
   }
   // Create script exception with stacktrace from oom-error.
   ScriptException exception =
       newInternalError(realm.defaultContext(), Messages.Key.OutOfMemoryVM);
   exception.setStackTrace(e.getStackTrace());
   handleException(realm, exception);
 }
Ejemplo n.º 4
0
 public static void fullGC(boolean verbose) {
   if (verbose)
     System.out.print(
         new Date().toString()
             + ' '
             + String.valueOf((RUNTIME.totalMemory() - RUNTIME.freeMemory()) / 1024L)
             + "Kb used");
   long isFree = RUNTIME.freeMemory();
   long wasFree;
   do {
     wasFree = isFree;
     RUNTIME.runFinalization();
     RUNTIME.gc();
     isFree = RUNTIME.freeMemory();
   } while (isFree > wasFree);
   if (verbose)
     System.out.println(
         " --> "
             + String.valueOf((RUNTIME.totalMemory() - RUNTIME.freeMemory()) / 1024L)
             + "Kb used");
 }
Ejemplo n.º 5
0
  @Override
  public DiskData build() throws IOException {
    meta.assign(parser);
    meta.dirty = true;

    // calculate optimized output buffer sizes to reduce disk fragmentation
    final Runtime rt = Runtime.getRuntime();
    final long max = Math.min(1 << 22, rt.maxMemory() - rt.freeMemory() >> 2);
    int bs = (int) Math.min(meta.filesize, max);
    bs = Math.max(IO.BLOCKSIZE, bs - bs % IO.BLOCKSIZE);

    // drop old database (if available) and create new one
    DropDB.drop(dbname, sopts);
    sopts.dbpath(dbname).md();

    elemNames = new Names(meta);
    attrNames = new Names(meta);
    try {
      tout = new DataOutput(new TableOutput(meta, DATATBL));
      xout = new DataOutput(meta.dbfile(DATATXT), bs);
      vout = new DataOutput(meta.dbfile(DATAATV), bs);
      sout = new DataOutput(meta.dbfile(DATATMP), bs);

      final Performance perf = Prop.debug ? new Performance() : null;
      Util.debug(tit() + DOTS);
      parse();
      if (Prop.debug) Util.errln(" " + perf + " (" + Performance.getMemory() + ')');

    } catch (final IOException ex) {
      try {
        close();
      } catch (final IOException ignored) {
      }
      throw ex;
    }
    close();

    // copy temporary values into database table
    try (final DataInput in = new DataInput(meta.dbfile(DATATMP))) {
      final TableAccess ta = new TableDiskAccess(meta, true);
      for (; spos < ssize; ++spos) ta.write4(in.readNum(), 8, in.readNum());
      ta.close();
    }
    meta.dbfile(DATATMP).delete();

    // return database instance
    return new DiskData(meta, elemNames, attrNames, path, ns);
  }
Ejemplo n.º 6
0
  private void doClean(timerEvent ev) {
    // Cleaner event
    if (VERBOSE) System.err.println("-- Cleaning up packetTable");

    // Might cause some recent packets to be dropped
    packetTable.clear();

    if (VERBOSE) {
      Runtime r = Runtime.getRuntime();
      System.err.println(
          "TOTAL: " + r.totalMemory() / 1024 + "KB FREE: " + r.freeMemory() / 1024 + "KB");
    }

    // Reregister timer event
    timer.registerEvent(CLEAN_TIMER_FREQUENCY, ev, mySink);
  }
Ejemplo n.º 7
0
 public String toString() {
   String result = "f=" + (runtime.freeMemory() / MEGA) + "/";
   result += "t=" + (runtime.totalMemory() / MEGA) + "/";
   result += "m=" + (runtime.maxMemory() / MEGA) + "Mb";
   return result;
 }
Ejemplo n.º 8
0
 public static long getUsedMemory() {
   Runtime rt = Runtime.getRuntime();
   return rt.totalMemory() - rt.freeMemory();
 }