Archive
LG 엑스캔버스 하드 디스크 교체 Tip
Singleton pattern
The solution of Bill Pugh
University of Maryland Computer Science researcher Bill Pugh has written about the code issues underlying the Singleton pattern when implemented in Java.[8] Pugh’s efforts on the “Double-checked locking” idiom led to changes in the Java memory model in Java 5 and to what is generally regarded as the standard method to implement Singletons in Java. The technique known as the initialization on demand holder idiom, is as lazy as possible, and works in all known versions of Java. It takes advantage of language guarantees about class initialization, and will therefore work correctly in all Java-compliant compilers and virtual machines.
The nested class is referenced no earlier (and therefore loaded no earlier by the class loader) than the moment that getInstance() is called. Thus, this solution is thread-safe without requiring special language constructs (i.e. volatile or synchronized).
public class Singleton {
// Private constructor prevents instantiation from other classes
// (외부에서 인스턴스 생성을 막기 위함)
private Singleton() {
super();
}
/**
* SingletonHolder is loaded on the first execution of Singleton.getInstance()
* or the first access to SingletonHolder.INSTANCE, not before.
*/
private static class SingletonHolder {
public static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
참고: Wikipedia Link
jni for android with ndk
android 에서 native application 을 이용하기 위해서는 다음과 같은 과정을 거치면 된다.
Collection To Enumeration
List<String> list = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
list.add(i + "");
}
System.out.println("use for() loop");</pre>
for (String value : list) {
System.out.println(value);
}
Enumeration<String> enumeredList = Collections.enumeration(list);
System.out.println("use while() loop"); while (enumeredList.hasMoreElements()) {
System.out.println(enumeredList.nextElement());
}
Hello world!
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!