Skip to content

Instantly share code, notes, and snippets.

View 做有意义的事
<h1>发觉自己的爱好!做有意义的事,倾听</h1>
View gist:1803350
public class Test{
public String a = "hello";
}
View Singleton
/**
* see http://caterpillar.onlyfun.net/Gossip/DesignPattern/SingletonPattern.htm
* http://www.jackforfun.com/2007/07/java-synchronized.html
*/
public class Singleton {
private static Singleton instance = null;
private Singleton(){}
public static Singleton getInstance() {
if (instance == null){
synchronized(Singleton.class){
View 剪刀石头布
package test;
import java.util.Scanner;
public class ScissorStoneCloth {
/**
* @param args
*/
public static void main(String[] args) {
View java io.java
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
if (destFile.exists() && destFile.isDirectory()) {
throw new IOException("Destination '" + destFile + "' exists but is a directory");
}
FileInputStream fis = null;
FileOutputStream fos = null;
FileChannel input = null;
FileChannel output = null;
try {
@doubledouble
doubledouble / SingleInstance.java
Last active Oct 6, 2015
SingleInstance原来可以这么写
View SingleInstance.java
public class SingleInstance {
private static class InstanceHolder {
public static final SingleInstance instance = new SingleInstance();
}
public static SingleInstance getInstance() {
return InstanceHolder.instance;
}
}
View SingletonEnum
public enum SingletonEnum {
/**
* 定义一个枚举的元素,它就代表了Singleton的一个实例。
*/
uniqueInstance;
/**
* 单例可以有自己的操作
*/
View jvm内存模型
jvm内存模型
---JMM就是java解决多线程下内存共享的一个模型,与内存分区管理是不同的层面!
根据线程私有和线程共享来看:
线程私有:
---程序计数器:如果正在执行Java方法,则指向虚拟机字节码指令的地址,如果是native的,这个计算器的值为空。
---虚拟机栈:保存本地变量、操作数栈、动态链接、方法出口等信息。为执行java方法服务。
View AbstractTestBean
package com.iteye.common.test;
import junit.framework.TestCase;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
View MD5Util
/*
* Classname : MD5Util
* Create Date : Aug 15, 2006
*/
import java.security.MessageDigest;
/**
*