Java Runtime Class

자바 2020. 7. 4. 16:33

Runtime

- Runtime 클래스는 프로그램과 운영체제 간의 상호 작용을 위한 메서드들이 정의되어 있다

 

- 프로그램이 실행이 되면 이미 Runtime 클래스의 객체를 생성해서 가지고 있으며 이 객체의 주소 값을 얻어와서 사용하면 된다

 

대표 메서드

- totalMemory( ) : 메모리 전체의 양을 알아온다

 

- freeMemory( ) : 여유 메모리 양을 알아온다

 

- exec( ) : 운영체제에게 명령어를 전달한다

 

- gc( ) : 메모리를 청소해준다

 

RuntimeClass.java

--------------------------------------------------------------------------------------------------

import java.util.Vector;

 

// Runtime 객체를 얻어온다

Runtime run = Runtime.getRuntime( );

 

// 메모리량

long total = run.totalMemory( );

long free = run.freeMemory( );

long used = total - free;

System.out.println("총 메모리" + total);

System.out.println("여유 메모리" + free);

System.out.println("사용 메모리" + used);

 

// 프로그램 실행

try{

    run.exec("calc.exe");

    run.exec("notepad.exe");

    run.exec("explorer.exe http://www,naver.com");

}catch(Exception e) { }

 

Vector v = new Vector( );

v = null;

run.gc( );

System.gc( );

--------------------------------------------------------------------------------------------------

'자바' 카테고리의 다른 글

Java StringBuffer  (0) 2020.07.06
Java String  (0) 2020.07.04
Java wrapper  (0) 2020.07.04
자바 예외처리  (0) 2020.06.30
스레드의 동기화  (0) 2020.06.28
Posted by khon98
,