美文网首页
Retrofit单例

Retrofit单例

作者: 天之大任 | 来源:发表于2016-03-13 19:18 被阅读757次

点击打开

上面连接是rxjava和retrofit结合使用案例

public class DrakeetFactory {

   protected static final Object monitor = new Object();

   static GankApi sGankIOSingleton = null;

   static DrakeetApi sDrakeetSingleton = null;

   public static final int meizhiSize = 10;

   public static final int gankSize = 5;

   public static GankApi getGankIOSingleton() {

       synchronized (monitor) {

           if (sGankIOSingleton == null) {

               sGankIOSingleton = new DrakeetRetrofit().getGankService();

           }

           return sGankIOSingleton;

       }

   }

   public static DrakeetApi getDrakeetSingleton() {

       synchronized (monitor) {

           if (sDrakeetSingleton == null) {

               sDrakeetSingleton = new DrakeetRetrofit().getDrakeetService();

           }

           return sDrakeetSingleton;

       }

   }

}

相关文章

  • Retrofit单例

    点击打开 上面连接是rxjava和retrofit结合使用案例 public class DrakeetFacto...

  • 网络加载框架 - Retrofit-KT

    实战时候使用KT,进行Retrofit网络请求:使用单例模式, 成员变量private val retrofit:...

  • 网摘

    单例模式封装 RxJava+Retrofit 网络请求 https://blog.csdn.net/louyuli...

  • Retrofit 分析

    先上一个RetrofitHelper 使用kotlin的默认单例模式 Retrofit.java中create方法...

  • 设计模式汇总(ongoing)

    单例模式 工厂方法模式 抽象工厂模式 模板方法模式 建造者模式 代理模式Binder 通信retrofit 使用动...

  • Android Retrofit 工作原理解析

    本文以 Retrofit 整合 RxJava 为例,介绍 Retrofit 的工作原理,使用 Retrofit 2...

  • Android设计模式总结

    单例模式:饿汉单例模式://饿汉单例模式 懒汉单例模式: Double CheckLock(DCL)实现单例 Bu...

  • IOS单例模式的底层原理

    单例介绍 本文源码下载地址 1.什么是单例 说到单例首先要提到单例模式,因为单例模式是单例存在的目的 单例模式是一...

  • 【设计模式】单例模式

    单例模式 常用单例模式: 懒汉单例模式: 静态内部类单例模式: Android Application 中使用单例模式:

  • 2020-11-02-Spring单例 vs. 单例模式

    Spring 单例不是 Java 单例。本文讨论 Spring 的单例与单例模式的区别。 前言 单例是 Sprin...

网友评论

      本文标题:Retrofit单例

      本文链接:https://www.haomeiwen.com/subject/syqflttx.html