Skip to content

Instantly share code, notes, and snippets.

View simonwoo's full-sized avatar
💭
I may be slow to respond.

Chong WU simonwoo

💭
I may be slow to respond.
View GitHub Profile
@simonwoo
simonwoo / java equals() and hashCode().md
Last active August 29, 2015 14:20
java equals() and hashCode()

Defining equality

The Object class has two methods for making inferences about an object's identity: equals() and hashCode(). In general, if you override one of these methods, you must override both, as there are important relationships between them that must be maintained. In particular, if two objects are equal according to the equals() method, they must have the same hashCode() value (although the reverse is not generally true). The semantics of equals() for a given class are left to the implementer; defining what equals() means for a given class is part of the design work for that class. The default implementation, provided by Object, is simply reference equality:

public boolean equals(Object obj) { 
    return (this == obj); 
  }

Under this default implementation, two references are equal only if they refer to the exact same object. Similarly, the default implementation of hashCode() provided by Object is derived by mapping the memory address of the object to an intege

/**
     * Override equals() method for comparing two columns.
     * 
     * @return boolean.
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
 return true;

编程语言:

  • Effictive Java
  • 深入理解Java虚拟机
  • Java程序员修炼之道
  • Java并发编程实践
  • Java puzzlers
  • OSGI实战
  • How tomcat works

编程语言理论:

angular.module('restlet.testpre2', [])
.provider('testpre2', function () {
'use strict';
var endpoint = 'https://testpre2.apihive.com/v1';
var defaultHeaders = {};
var defaultQueryParameters = {};
/**
@simonwoo
simonwoo / design.md
Last active October 6, 2015 08:30
persistence layer and business logic layer
  • The persistence layer deals with persisting (storing and retrieving) data from a data store (such as a database, for example).

  • The business logic layer contains contains code which works with the data, processing it according to the rules of the business logic.

  • No, the persistence layer is the set of classes that manage the actual reading and writing of data to persistent storage - the DAOs and other data service objects.

  • The business logic should ideally never know how that data gets read or written. It should use the persistence layer to get and save the data, but its function is to do the abstract functions of the business such as creating a new account (but not the Hibernate functions of actually storing or retrieving account records), calculating service fees and penalties, calculating shipping fees, managing inventory, creating picking and packing lists and so forth.

Guava provides a very powerful memory based caching mechanism by an interface LoadingCache<K,V>. Values are automatically loaded in the cache and it provides many utility methods useful for caching needs.

if (failedRows.isEmpty()) {

                createAndStoreMessage(store, version, CellTraceLevel.INFO,
                        "Bulk data import successful.",
                        persistenceManager);

            } else {

                final String titleMessage;
angular.module('apiClient', [ 'restlet.myApi' ])

  .config(function (myApiProvider) {
    // Sets the endpoint
    myApiProvider.setEndpoint('https://angular.apihive.com/v1');
    // Sets the basic authentication
    myApiProvider.setBasicAuth('c6524b5c-5ba1-4a96-80c1-b5ed1267d90e', '84ce6ef6-55bf-4bed-a89e-86bd34d9c061');
  })

This article will discuss about Thread pool that can reuse previously constructed threads when they are available. From Java 5.0+ one can get such pool from Executors using following method – public static ExecutorService newCachedThreadPool() Creates a thread pool that creates new threads as needed, but will reuse previously constructed threads when they are available. These pools will typically improve the performance of programs that execute many short-lived asynchronous tasks. Calls to execute will reuse previously constructed threads if available. If no existing thread is available, a new thread will be created and added to the pool. Threads that have not been used for sixty seconds are terminated and removed from the cache. Thus, a pool that remains idle for long enough will not consume any resources. Note that pools with similar properties but different details (for example, timeout parameters) may be created using ThreadPoolExecutor constructors.

Example - Suppose we have 100 properties files in a