Skip to content

Instantly share code, notes, and snippets.

View hackdapp's full-sized avatar
🦖
On vacation

hackdapp hackdapp

🦖
On vacation
View GitHub Profile
@hackdapp
hackdapp / gist:5748600c35b337a1d503bb7534ff85ff
Created July 19, 2017 10:41
jpa查询指定字段并填充至自定义类
public interface ChannelRepository extends JpaRepository<Channel, Long>{
@Query(value = "select new com.reyun.lizard.service.model.KeyValue(str(a.channel),a.surl) from Campaign a where a.channel in (?1)")
List<KeyValue> findSurl(List<Long> channels);
}
@hackdapp
hackdapp / SingletonOne.java
Created September 4, 2017 04:30
单例实现 缺点: 多线程环境下存在多次实例化问题
public class SingletonOne
{
private static SingletonOne singletonOne = null;
private SingletonOne()
{
}
public static SingletonOne getInstance()
{
@hackdapp
hackdapp / SingletonTwo.java
Created September 4, 2017 04:34
缺点: 线程安全, 但性能差
public class SingletonTwo
{
private static SingletonTwo singletonTwo;
private SingletonTwo()
{
}
public static synchronized SingletonTwo getSingletonTwo()
{
@hackdapp
hackdapp / SingletonThreee.java
Created September 4, 2017 04:36
在多线程环境下,有可能在实例未完成的情况下进行调用出现错误
/**
* description:
* 在多线程环境下,有可能在实例未完成的情况下进行调用出现错误
* @author nolan
* @date 09/08/2017
*/
public class SingletonThreee
{
private static SingletonThreee singletonThreee;
public class SingleFour
{
private static class SingleHolder {
private static SingleFour instance = new SingleFour();
}
public static SingleFour getInstance(){
return SingleHolder.instance;
}
}
@hackdapp
hackdapp / SingletonFive.java
Created September 4, 2017 04:40
推荐使用
public class SingletonFive
{
private static SingletonFive singletonFive;
private SingletonFive()
{
}
public static SingletonFive getInstance()
{
@hackdapp
hackdapp / SingletonThree.java
Created September 4, 2017 05:05
多线程环境下,有可能在实例未完成的情况下出现程序调用错误
/**
* description:
* 在多线程环境下,有可能在实例未完成的情况下进行调用出现错误
* @author nolan
* @date 09/08/2017
*/
public class SingletonThree
{
private static SingletonThree singletonThree;
@hackdapp
hackdapp / SingletonThree.java
Created September 4, 2017 05:22
实例化过程中,禁止指令乱排序优化
public class SingletonThree
{
private static volatile SingletonThree singletonThree;
private SingletonThree()
{
}
public static SingletonThree getInstace()
{
public interface Logger
{
void log(String message);
}
public class XMLLogger
implements Logger
{
public void log(String message)
{
}
}