jdk
SPI机制
From Java documentation:
A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific implementation of a service. The classes in a provider typically implement the interfaces and subclass the classes defined in the service itself. Service providers can be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Providers can also be made available by adding them to the application’s class path or by some other platform-specific means—–By wiki
大致意思为:服务提供者是服务的特定实现。提供程序中的类通常实现接口,并子类化服务本身中定义的类。服务提供程序可以扩展的形式安装在Java平台的实现中,也就是说,将jar文件放置在任何常用扩展目录中。也可以通过将提供者添加到应用程序的类路径或通过其他一些特定于平台的方式来使提供者可用。
实现机制
通知java.util.ServiceLoader类查找以服务接口命名的文件,加载并实例化指定的jar包服务,好处是不同厂商可以对同个接口进行不同的操作,比如java.sql.Driver通过指定驱动类进行操作等。但是这样子加载速度可能慢,且不够灵活。