-
Notifications
You must be signed in to change notification settings - Fork 0
조희승 2주차 학습 일지
huiseung edited this page Jul 8, 2024
·
5 revisions
- Socket
- jar 파일
- build.gradle
- Stream
-
클래스 로더는 lazy-loading 을 사용한다
- 실행 시점이 아니라 클래스 사용 시점에 메모리를 로드
- 로드한 클래스의 정보를 담은 java.lang.Class 를 만든다
-
로딩 절차
- jvm은 System ClassLoader에게 로딩 요청
- System ClassLoader -> Platform ClassLoader -> Bootstrap ClassLoader 순으로 로딩 요청
- Bootstrap ClassLoader -> Platform ClassLoader -> System ClassLoader 순으로 처리할 수 있는지 확인해 가능하면 로드, 아니면 자식에게 로드를 명령
- System ClassLoader 가 로드 할 수 없으면 ClassNotFoundException
-
java8까지 클래스 로더는 3 종류
- Bootstrap Class Loader
- 출력시 null 로 표기, parent가 없다
- Extension Class Loader
- Application Class Loader
- classpath의 클래스 파일 로딩
- Bootstrap Class Loader
-
java9 부터
- Bootstrap ClassLoader
- java.base 패키지 하위의 중요 클래스만 로딩하게 역할이 축소
- Platform ClassLoader
- Extension Class Loader에서 이름 변경
- System ClassLoader
- Application Class Loader에서 이름 변경
- Bootstrap ClassLoader
package java.lang;
public abstract class ClassLoader {
private final ClassLoader parent;
private static volatile ClassLoader scl; // system class loader
}
public static InputStream getSystemResourceAsStream(String name) {
URL url = getSystemResource(name);
try {
return url != null ? url.openStream() : null;
} catch (IOException e) {
return null;
}
}
public static URL getSystemResource(String name) {
return getSystemClassLoader().getResource(name);
}
@CallerSensitive
public static ClassLoader getSystemClassLoader() {
switch (VM.initLevel()) {
case 0:
case 1:
case 2:
// the system class loader is the built-in app class loader during startup
return getBuiltinAppClassLoader();
case 3:
String msg = "getSystemClassLoader cannot be called during the system class loader instantiation";
throw new IllegalStateException(msg);
default:
// system fully initialized
assert VM.isBooted() && scl != null;
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
checkClassLoaderPermission(scl, Reflection.getCallerClass());
}
return scl;
}
}
public URL getResource(String name) {
Objects.requireNonNull(name);
URL url;
if (parent != null) {
url = parent.getResource(name);
} else {
url = BootLoader.findResource(name);
}
if (url == null) {
url = findResource(name);
}
return url;
}
protected URL findResource(String name) {
return null;
}
public class BootLoader {
private BootLoader() {
}
}
- 사전 의미, 흐르는 시냇물
- 프로그램 외부에서 들어오거나 외부로 나가는 데이터 통로
- 외부에서 들어노는 데이터 통로
public abstract class InputStream implements Closeable {
// 1 byte 씩 읽기, 읽은 byte 크기 반환
public abstract int read() throws IOException;
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
public void close() throws IOException {}
}