Skip to content

[additional] ServiceLoader #3

Description

@wooyounggggg

연관 챕터

#1

조사 내용

책 내용 중 ServiceLoader라는 개념이 등장합니다. 관련하여, ServiceLoader가 어떻게 동작하는지 찾아보았습니다.

ServiceLoader는 대략 아래와 같은 형태로 사용할 수 있습니다.

/* SomeService.java */
public interface SomeService {
    doSomething();
}
...
public static void main(String[] args) {
    ServiceLoader<SomeService> loader = ServiceLoader.load(SomeService.class);
    Optional<SomeService> someServiceOptional = loader.findFirst();
    someServiceOptional.ifPresent(s -> {
        s.doSomething();
    });
}

위의 코드에서, ServiceLoader는 SomeService의 subclass를 검색하여 loader에 로드합니다.

  • 수정중

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions