mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
494c70b9e6
commit
6dfb495278
@ -16,9 +16,13 @@ import org.dromara.hutool.core.exception.HutoolException;
|
|||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import org.dromara.hutool.core.thread.ThreadUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class SingletonTest {
|
public class SingletonTest {
|
||||||
|
|
||||||
@ -65,4 +69,21 @@ public class SingletonTest {
|
|||||||
static class C{
|
static class C{
|
||||||
private B b = Singleton.get(B.class);
|
private B b = Singleton.get(B.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void issue3435Test() {
|
||||||
|
final String key = "123";
|
||||||
|
final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
threadPoolExecutor.execute(() -> {
|
||||||
|
Singleton.get(key, () -> {
|
||||||
|
System.out.println(key);
|
||||||
|
return "123";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtil.sleep(5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
package org.dromara.hutool.db.ds;
|
package org.dromara.hutool.db.ds;
|
||||||
|
|
||||||
import org.dromara.hutool.core.io.IoUtil;
|
import org.dromara.hutool.core.io.IoUtil;
|
||||||
|
import org.dromara.hutool.core.lang.Singleton;
|
||||||
import org.dromara.hutool.core.map.MapUtil;
|
import org.dromara.hutool.core.map.MapUtil;
|
||||||
import org.dromara.hutool.core.map.SafeConcurrentHashMap;
|
import org.dromara.hutool.core.map.SafeConcurrentHashMap;
|
||||||
import org.dromara.hutool.core.spi.SpiUtil;
|
import org.dromara.hutool.core.spi.SpiUtil;
|
||||||
@ -42,17 +43,13 @@ public class DSPool implements Closeable {
|
|||||||
|
|
||||||
private static final String CONNECTION_PREFIX = "connection.";
|
private static final String CONNECTION_PREFIX = "connection.";
|
||||||
|
|
||||||
private static class SingletonHolder {
|
|
||||||
private static final DSPool INSTANCE = new DSPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单例池对象
|
* 获取单例池对象
|
||||||
*
|
*
|
||||||
* @return 数据源池
|
* @return 数据源池
|
||||||
*/
|
*/
|
||||||
public static DSPool getInstance() {
|
public static DSPool getInstance() {
|
||||||
return SingletonHolder.INSTANCE;
|
return Singleton.get(DSPool.class.getName(), DSPool::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,10 +37,8 @@ import com.github.houbb.pinyin.util.PinyinHelper;
|
|||||||
*/
|
*/
|
||||||
public class HoubbEngine implements PinyinEngine {
|
public class HoubbEngine implements PinyinEngine {
|
||||||
|
|
||||||
/**
|
// 汉字拼音输出的格式
|
||||||
* 汉字拼音输出的格式
|
private PinyinStyleEnum format;
|
||||||
*/
|
|
||||||
PinyinStyleEnum format;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
|
@ -40,18 +40,31 @@ import com.github.stuxuhai.jpinyin.PinyinHelper;
|
|||||||
public class JPinyinEngine implements PinyinEngine {
|
public class JPinyinEngine implements PinyinEngine {
|
||||||
|
|
||||||
//设置汉子拼音输出的格式
|
//设置汉子拼音输出的格式
|
||||||
PinyinFormat format;
|
private PinyinFormat format;
|
||||||
|
|
||||||
public JPinyinEngine(){
|
/**
|
||||||
|
* 构造
|
||||||
|
*/
|
||||||
|
public JPinyinEngine() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JPinyinEngine(final PinyinFormat format){
|
/**
|
||||||
|
* 构造
|
||||||
|
*
|
||||||
|
* @param format {@link PinyinFormat}
|
||||||
|
*/
|
||||||
|
public JPinyinEngine(final PinyinFormat format) {
|
||||||
init(format);
|
init(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(PinyinFormat format){
|
/**
|
||||||
if(null == format){
|
* 初始化格式
|
||||||
|
*
|
||||||
|
* @param format 格式{@link PinyinFormat}
|
||||||
|
*/
|
||||||
|
public void init(PinyinFormat format) {
|
||||||
|
if (null == format) {
|
||||||
// 不加声调
|
// 不加声调
|
||||||
format = PinyinFormat.WITHOUT_TONE;
|
format = PinyinFormat.WITHOUT_TONE;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombi
|
|||||||
public class Pinyin4jEngine implements PinyinEngine {
|
public class Pinyin4jEngine implements PinyinEngine {
|
||||||
|
|
||||||
//设置汉子拼音输出的格式
|
//设置汉子拼音输出的格式
|
||||||
HanyuPinyinOutputFormat format;
|
private HanyuPinyinOutputFormat format;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
|
@ -41,21 +41,22 @@ public class TinyPinyinEngine implements PinyinEngine {
|
|||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
*/
|
*/
|
||||||
public TinyPinyinEngine(){
|
public TinyPinyinEngine() {
|
||||||
this(null);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造
|
* 构造
|
||||||
|
*
|
||||||
* @param config 配置
|
* @param config 配置
|
||||||
*/
|
*/
|
||||||
public TinyPinyinEngine(final Pinyin.Config config){
|
public TinyPinyinEngine(final Pinyin.Config config) {
|
||||||
Pinyin.init(config);
|
Pinyin.init(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPinyin(final char c) {
|
public String getPinyin(final char c) {
|
||||||
if(!Pinyin.isChinese(c)){
|
if (!Pinyin.isChinese(c)) {
|
||||||
return String.valueOf(c);
|
return String.valueOf(c);
|
||||||
}
|
}
|
||||||
return Pinyin.toPinyin(c).toLowerCase();
|
return Pinyin.toPinyin(c).toLowerCase();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user