代码改变世界

阅读排行榜

Effective Java 68 Prefer executors and tasks to threads

2014-05-02 23:39 by 小郝(Kaibo Hao), 604 阅读, 收藏,
摘要: The general mechanism for executing tasks is the executor service. If you think in terms of tasks and let an executor service execute them for you, you gain great flexibility in terms of selecting appropriate execution policies. In essence, the Executor Framework does for execution what the Collections Framework did for aggregation. 阅读全文

Effective Java 64 Strive for failure atomicity

2014-04-28 06:02 by 小郝(Kaibo Hao), 603 阅读, 收藏,
摘要: Any generated exception that is part of a method's specification should leave the object in the same state it was in prior to the method invocation. Where this rule is violated, the API documentation should clearly indicate what state the object will be left in. 阅读全文

Effective Java 67 Avoid excessive synchronization

2014-05-01 22:17 by 小郝(Kaibo Hao), 595 阅读, 收藏,
摘要: To avoid deadlock and data corruption, never call an alien method from within a synchronized region. More generally, try to limit the amount of work that you do from within synchronized regions. When you are designing a mutable class, think about whether it should do its own synchronization. In the modern multicore era, it is more important than ever not to synchronize excessively. Synchronize your class internally only if there is a good reason to do so, and document your decision clearly (Item 阅读全文

Effective C# 学习笔记(三十七) 警惕并行处理中的异常处理

2011-07-26 23:57 by 小郝(Kaibo Hao), 585 阅读, 收藏,
摘要: 若一个异常到达了调用该线程的方法时,该线程也就终止运行了。而并行编程使用AggregateException类型来处理发生在子线程中的各类异常,而这些异常存储在AggregateException对象的InnerExceptions属性中。处理异常策略的原则是:处理你能恢复到正常状态的异常,抛出其他那些异常。 阅读全文

Effective Java 17 Design and document for inheritance or else prohibit it

2014-03-12 11:21 by 小郝(Kaibo Hao), 577 阅读, 收藏,
摘要: Principles The class must document its self-use of overridable methods. A class may have to provide hooks into its internal workings in the form of judiciously chosen protected methods. The only way to test a class designed for inheritance is to write subclasses. You must test your class by writing subclasses before you release it. Constructors must not invoke overridable methods. This happens when there is a method which can be override by subclass calls the subclass's const 阅读全文

Effective Java 33 Use EnumMap instead of ordinal indexing

2014-03-27 15:15 by 小郝(Kaibo Hao), 573 阅读, 收藏,
摘要: It is rarely appropriate to use ordinals to index arrays: use EnumMap instead. If the relationship that you are representing is multidimensional, use EnumMap<..., EnumMap<...>>. 阅读全文

Effective C# 学习笔记(三十四)避免在子类中重载父类的方法

2011-07-18 12:48 by 小郝(Kaibo Hao), 572 阅读, 收藏,
摘要: 如题,在子类中重载(overload)父类的方法会给你类的客户分不清同样的方法名在运行时到底运行的是哪个类的方法,而且对于C#4.0前后版本的逆变协变支持的不同,你的重载(对于带范型参数的方法)也会有截然相反的结果,所以还是尽量不要再子类中重载父类中的方法。 首先,要分清orverload和override两个单词的中文解释。 overload为重载即表示方法通过参数个数、参数类型的不同对同名方法的另一逻辑实现,等于创建了一个新的同名方法,与原有方法并存。 override为覆写,顾名思义就是覆盖掉父类同名方法,形参列表是与父类一致的。 阅读全文

Effective Java 76 Write readObject methods defensively

2014-05-10 15:20 by 小郝(Kaibo Hao), 569 阅读, 收藏,
摘要: Anytime you write a readObject method, adopt the mind-set that you are writing a public constructor that must produce a valid instance regardless of what byte stream it is given. Do not assume that the byte stream represents an actual serialized instance. 阅读全文

Effective Java 29 Consider typesafe heterogeneous containers

2014-03-23 08:38 by 小郝(Kaibo Hao), 568 阅读, 收藏,
摘要: The normal use of generics, exemplified by the collections APIs, restricts you to a fixed number of type parameters per container. You can get around this restriction by placing the type parameter on the key rather than the container. You can use Class objects as keys for such typesafe heterogeneous containers. A Class object used in this fashion is called a type token. You can also use a custom key type. For example, you could have a Database Rowtype representing a database row (the container), 阅读全文

Effective Java 01 Consider static factory methods instead of constructors

2014-02-22 20:22 by 小郝(Kaibo Hao), 566 阅读, 收藏,
摘要: Unlike constructors, they have names. They are not required to create a new object each time they're invoked(Flyweight pattern). It can return an object of any subtype of their return type.(This gives you great flexibility in choosing the class of the returned object. ) 阅读全文
上一页 1 2 3 4 5 6 7 8 ··· 21 下一页