Retrofit单例

2016-03-13  本文已影响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;

       }

   }

}

上一篇 下一篇

猜你喜欢

热点阅读