The Traps of Frameworks

When I interview a Java developer, if I see Spring Boot or Spring on the candidate’s resume, I may start with a simple question: “What is the default scope for a Spring bean”? Most people would get it right. I would then follow with a tricky question: “Does Spring make sure a Singleton bean thread-safe?” or “Does developer need to do anything to make sure a Singleton bean thread-safe?”.

When I say “tricky”, not because it’s tricky technically, but because half interviewees have no idea. The other half who correctly answered don’t always demonstrate solid understanding of Singleton and thread-safety. It’s okay to guess at an interview I guess.

Spring Boot is one of those popular frameworks for Java developers. Like most other Java frameworks, it provides proven reusable libraries and increases productivity. Some developers can probably make a living by simply being good at it.

However, because it encapsulates the interpretation of various Java Specifications, hides the complexity of design and implementation, often the framework itself imposes a serious impediment for developers to understand the underlining fundamentals.

Many Spring Boot developers don’t know Spring Boot is just a framework on top of another popular framework Spring Framework, which was initially a framework for Java Servlet applications. Most freshly-minted Spring Boot developers never heard of Servlet, not to mention web.xml. They only know their Spring Boot applications, “just run”. They never know why and how it runs.

Because of that, they never think of what the underlining Servlet Container is, what the default configurations (like Max Concurrent Requests) are, and how to fine tune those configurations. Imagine asking them to write a Java Web Application without Spring Boot?

Frameworks tend to wrap a lot of default features and behaviors under the hood, just to name a few: default Encryption Algorithm, default Socket Timeout, default Retry Strategy.

In the past, Frameworks might have configuration property for each “feature”, but this has changed in the recent years. Nowadays, Framework authors tend to favor “Convention over configuration”. Old configuration files are replaced by annotations with “sensible defaults”. Moreover, many of the features and behaviors are “discovered” automatically based on your running environments, like system properties, environment variables and what is in the class-path.

Several years back, I led a framework team. We built a Framework as the foundation for a slew of web applications that support multi-million $ business. We worked very hard to support all major features by default, and still allow each application to extend and override each feature by configuration and automatic discovery. I learned first hand, it’s even harder for application developers to fully understand how each feature worked and how to extend or override them.

Naturally, due to the lack of visibility and transparency of frameworks, people makes a lot of assumptions about frameworks, such as Singleton bean thread-safety. Some of the assumptions will definitely haunt the team down the road if the technical leads on the team didn’t review the design and code carefully.

Overtime, frameworks will evolve or die. If you ever worked with Struts 1.x framework, and if you didn’t understand Java Servlet, you would have a difficult time to migrate your applications to Struts 2.x or Spring.

Frameworks are your tools, not your crutches. If you don’t think out of the box of Spring Boot, you can’t professionally outgrow Spring Boot. Simple. Period.

That is true to other frameworks too.

Frameworks can help you get started quickly, but understanding the underlining principles will help you in the long run.

Android 通用流行框架大全





1. 缓存

名称 描述
DiskLruCache Java实现基于LRU的磁盘缓存



名称 描述
Android Universal Image Loader 一个强大的加载,缓存,展示图片的库
Picasso 一个强大的图片下载与缓存的库
Fresco 一个用于管理图像和他们使用的内存的库
Glide 一个图片加载和缓存的库


3. 图片处理

名称 描述
Picasso-transformations 一个为Picasso提供多种图片变换的库
Glide-transformations 一个为Glide提供多种图片变换的库
Android-gpuimage 基于OpenGL的Android过滤器


4. 网络请求

名称 描述
Android Async HTTP Android异步HTTP库
AndroidAsync 异步Socket,HTTP(客户端+服务器),WebSocket,和socket.io库。基于NIO而不是线程。
OkHttp 一个Http与Http/2的客户端
Retrofit 类型安全的Http客户端
Volley Google推出的Android异步网络请求框架和图片加载框架


5. 网络解析

名称 描述
Gson 一个Java序列化/反序列化库,可以将JSON和java对象互相转换
Jackson Jackson可以轻松地将Java对象转换成json对象和xml文档,同样也可以将json、xml转换成Java对象
Fastjson Java上一个快速的JSON解析器/生成器
HtmlPaser 一种用来解析单个独立html或嵌套html的方式
Jsoup 一个以最好的DOM,CSS和jQuery解析html的库


6. 数据库

名称 描述
OrmLite JDBC和Android的轻量级ORM java包
Sugar 用超级简单的方法处理Android数据库
GreenDAO 一种轻快地将对象映射到SQLite数据库的ORM解决方案
ActiveAndroid 以活动记录方式为Android SQLite提供持久化
SQLBrite SQLiteOpenHelper 和ContentResolver的轻量级包装
Realm 移动数据库:一个SQLite和ORM的替换品


7. 依赖注入

名称 描述
ButterKnife 将Android视图和回调方法绑定到字段和方法上
Dagger2 一个Android和java快速依赖注射器。
AndroidAnotations 快速安卓开发。易于维护
RoboGuice Android平台的Google Guice


8. 图表

名称 描述
WilliamChart 创建图表的Android库
HelloCharts 兼容到API8的Android图表库
MPAndroidChart 一个强大的Android图表视图/图形库


9. 后台处理

名称 描述
Tape 一个轻快的,事务性的,基于文件的FIFO的库
Android Priority Job Queue 一个专门为Android轻松调度任务的工作队列


10. 事件总线

名称 描述
EventBus 安卓优化的事件总线,简化了活动、片段、线程、服务等的通信
Otto 一个基于Guava的增强的事件总线


11. 响应式编程

名称 描述
RxJava JVM上的响应式扩展
RxJavaJoins 为RxJava提供Joins操作
RxAndroid Android上的响应式扩展,在RxJava基础上添加了Android线程调度
RxBinding 提供用RxJava绑定Android UI的API
Agera Android上的响应式编程


12. Log框架

名称 描述
Logger 简单,漂亮,强大的Android日志工具
Hugo 在调试版本上注解的触发方法进行日志记录
Timber 一个小的,可扩展的日志工具


13. 测试框架

名称 描述
Mockito Java编写的Mocking单元测试框架
Robotium Android UI 测试
Robolectric Android单元测试框架



14. 调试框架

名称 描述
Stetho 调试Android应用的桥梁,使得可以利用Chrome开发者工具进行调试


15. 性能优化

名称 描述
LeakCanary 内存泄漏检测工具
ACRA Android应用程序崩溃报告