Skip to content

Instantly share code, notes, and snippets.

@zhugw
zhugw / gist:63e98f99098156e8173a
Last active December 4, 2015 06:55
spring boot devtools load beandozermapper twice and cause LinkageError sample
Foo project
@SpringBootApplication
public class FooApplication {
public static void main(String[] args) {
SpringApplication.run(FooApplication.class, args);
}
@Bean
public Mapper fooDozerBeanMapper() {
DozerBeanMapper mapper = BeanMapper.getDozerBeanMapper();
@zhugw
zhugw / gist:26938d33a61b376ca1a5
Created January 24, 2016 07:16
验证并发情况下的自定义订单流水号生成器是否会有重复
// 验证并发情况下的自定义订单流水号生成器是否会有重复
// 订单流水号生成器
public static String getOrderNo(){
String orderNo = "";
String date = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
Integer math = new Random().nextInt(1000);
orderNo = date+""+math;
return orderNo;
}
// 验证代码
@zhugw
zhugw / gist:5d17d6bbe03a9eba473c
Last active January 31, 2016 09:11
JsonPath 解析 json demo
```
[
{
"category": "tag_foo",
"tagPrice": [
{
"activeTagDictId": 370,
"activePrice": 39
},
{
@zhugw
zhugw / gist:d07d3764b252b52ab4c3
Created January 27, 2016 02:38
模拟异常对象过多导致频繁FullGC
//如何模拟异常堆栈占用内存过多导致频繁FulGC
//java.lang.StackTraceElement数据已经占用了85M
//目前的代码不能很好的重现该问题
package com.hlj.test;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
#write by wozi
#!/bin/bash
HOSTS=(
'root@101.251.1.1 7711'
'root@172.16.1.1 7711 password'
)
function show() {
echo 'ALL HOSTS'
echo '==============================='
for ((i=0; i<${#HOSTS[*]}; i++)); do
@zhugw
zhugw / gist:9e4b722f1ad5c626ca8a
Created February 20, 2016 13:39
验证并发更新库存
/**
* 验证并发update mysql数据库记录
* @param args
* @throws SQLException
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws SQLException, IOException, InterruptedException {
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
@zhugw
zhugw / gist:efd33b66a58824a86136
Created February 23, 2016 06:03
转盘抽奖算法demo
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* <pre>
* 转盘抽奖算法demo
/*******************************************************************************
* Copyright (c) 2005, 2014 springside.github.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
*******************************************************************************/
package org.springside.modules.nosql.redis;
import java.util.List;
import java.util.Map;
import java.util.Set;
@zhugw
zhugw / gist:0852f5f0ee38f07a8661d0e57db1853e
Created August 6, 2016 11:23
多线程模拟并发抽奖中礼帽和兑奖
package com.zhugw;
import org.apache.commons.lang3.RandomStringUtils;
import java.sql.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
@zhugw
zhugw / gist:1cdadc73358088a0989b5c3f36a92cac
Created August 14, 2016 13:44
验证Spring嵌套事务
package com.helijia.lottery.service;
import com.helijia.common.api.model.ApiException;
import com.helijia.lottery.dao.mapper.TestMapper;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;