-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from qqxx6661/dev_1.6.x
custom thread pool support
- Loading branch information
Showing
23 changed files
with
378 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
log-record-core/src/main/java/cn/monitor4all/logRecord/thread/DefaultThreadPoolProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cn.monitor4all.logRecord.thread; | ||
|
||
import cn.monitor4all.logRecord.configuration.LogRecordProperties; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.concurrent.CustomizableThreadFactory; | ||
|
||
import java.util.concurrent.LinkedBlockingQueue; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* 默认线程池提供者 | ||
*/ | ||
@Slf4j | ||
public class DefaultThreadPoolProvider implements ThreadPoolProvider { | ||
|
||
private final LogRecordProperties logRecordProperties; | ||
private static final ThreadFactory THREAD_FACTORY = new CustomizableThreadFactory("log-record-"); | ||
|
||
|
||
public DefaultThreadPoolProvider(LogRecordProperties logRecordProperties) { | ||
this.logRecordProperties = logRecordProperties; | ||
} | ||
|
||
@Override | ||
public ThreadPoolExecutor buildLogRecordThreadPool() { | ||
log.info("LogRecordThreadPool init poolSize [{}]", logRecordProperties.getThreadPool().getPoolSize()); | ||
int poolSize = logRecordProperties.getThreadPool().getPoolSize(); | ||
return new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(1024), THREAD_FACTORY, new ThreadPoolExecutor.AbortPolicy()); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
log-record-core/src/main/java/cn/monitor4all/logRecord/thread/ThreadPoolProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cn.monitor4all.logRecord.thread; | ||
|
||
|
||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
/** | ||
* 线程池提供者 | ||
*/ | ||
public interface ThreadPoolProvider { | ||
|
||
/** | ||
* 提供操作日志处理线程池 | ||
*/ | ||
ThreadPoolExecutor buildLogRecordThreadPool(); | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
log-record-core/src/main/java/cn/monitor4all/logRecord/util/JsonUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cn.monitor4all.logRecord.util; | ||
|
||
|
||
import com.alibaba.fastjson.JSON; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class JsonUtil { | ||
|
||
public static String safeToJsonString(Object object) { | ||
try { | ||
return JSON.toJSONString(object); | ||
} catch (Exception e) { | ||
log.error("safeToJsonString error, object {}", object, e); | ||
return object.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...test/java/cn/monitor4all/logRecord/springboot3/test/OperationLogCustomThreadPoolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cn.monitor4all.logRecord.springboot3.test; | ||
|
||
|
||
import cn.monitor4all.logRecord.bean.LogDTO; | ||
import cn.monitor4all.logRecord.springboot3.test.service.OperatorIdGetService; | ||
import cn.monitor4all.logRecord.springboot3.test.service.TestService; | ||
import cn.monitor4all.logRecord.springboot3.LogRecordAutoConfiguration; | ||
import cn.monitor4all.logRecord.springboot3.test.utils.TestHelper; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.EnableAspectJAutoProxy; | ||
import org.springframework.context.annotation.PropertySource; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
/** | ||
* 单元测试:自定义线程池 | ||
*/ | ||
@Slf4j | ||
@SpringBootTest | ||
@ContextConfiguration(classes = { | ||
LogRecordAutoConfiguration.class, | ||
OperatorIdGetService.class, | ||
TestService.class,}) | ||
@PropertySource("classpath:testCustomThreadPool.properties") | ||
@EnableAspectJAutoProxy(proxyTargetClass = true) | ||
public class OperationLogCustomThreadPoolTest { | ||
|
||
@Autowired | ||
private TestService testService; | ||
|
||
/** | ||
* 测试:用户传入自定义线程池 | ||
*/ | ||
@Test | ||
public void testCustomThreadPool() { | ||
TestHelper.addLock("testCustomThreadPool"); | ||
testService.testCustomThreadPool(); | ||
TestHelper.await("testCustomThreadPool"); | ||
LogDTO logDTO = TestHelper.getLogDTO("testCustomThreadPool"); | ||
|
||
Assertions.assertEquals(logDTO.getBizType(), "testCustomThreadPool"); | ||
} | ||
|
||
} |
Oops, something went wrong.