创建线程方式2-实现Runnable接口
这个和 Thread 基本类似都是最基础的多线程实现方式,唯一不同的点是这个实现的接口模式比较灵活,你的类实现了 Runnable 接口后还能去继承其他的父类
这个和 Thread 基本类似都是最基础的多线程实现方式,唯一不同的点是这个实现的接口模式比较灵活,你的类实现了 Runnable 接口后还能去继承其他的父类
这个是最基础的多线程使用方式了,但不推荐生产使用
第一个是因为Java 类不能支持多继承。如果你的类已经继承了另一个类,就不能再继承 Thread 类了。
第二个是 run 方法 和 Thread 对象 耦合在一起,不符合面向对象的设计原则。
这次我使用的试试 autodl 来部署我的 PaddleOCR ,哎公司不给我配 GPU 服务器
@Service 源码
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component // 看这里
public @interface Service {
// ...
}
@Controller 源码
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component // 看这里
public @interface Controller {
// ...
}
@Repository 源码
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented // 看这里
@Component
public @interface Repository {
// ...
}
@Service、 @Controller、@Repository
的 元注解 都应用了 @Component
,这就能看出来从核心功能上讲,@Service、 @Controller、@Repository
和 @Component
做的事情几乎完全一样:都是将一个类标识为 Spring Bean,交由 Spring 容器进行管理。但它们在语义和应用分层上有明确的区别。
@Controller
) : 接收 HTTP 请求,调用服务层。@Service
) : 处理核心业务逻辑。@Repository
) : 与数据库进行交互。@Component
是 Spring 框架中最基础、最通用的构造型注解。它的作用就是告诉 Spring:“请扫描这个类,为它创建一个实例(Bean),并放到 IoC 容器里管理起来。 ”