feat: 优化插件加载逻辑
This commit is contained in:
@@ -18,10 +18,17 @@ const JavaScriptTask = Java.type(base.getJavaScriptTaskClass().name)
|
||||
const threadCount = new AtomicInteger(0)
|
||||
const threadGroup = new ThreadGroup("@ccms/micro-task")
|
||||
const microTaskPool = new ThreadPoolExecutor(
|
||||
100, 200, 60, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue(1024),
|
||||
16, 32, 64, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue(64),
|
||||
new ThreadFactory((run: any) => new Thread(threadGroup, run, "@ccms/micro-task-" + threadCount.incrementAndGet()))
|
||||
)
|
||||
|
||||
declare global {
|
||||
interface Function {
|
||||
thread: any;
|
||||
}
|
||||
}
|
||||
|
||||
class Process extends EventEmitter {
|
||||
readonly version = base.version
|
||||
readonly versions = []
|
||||
@@ -72,6 +79,7 @@ class Process extends EventEmitter {
|
||||
try {
|
||||
microTaskPool.submit(new Callable({
|
||||
call: () => {
|
||||
callback.thread = Thread.currentThread();
|
||||
try {
|
||||
callback(args)
|
||||
} catch (origin: any) {
|
||||
@@ -89,6 +97,9 @@ class Process extends EventEmitter {
|
||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${callback.name || '<anonymous>'} exec exit!`)
|
||||
}
|
||||
if (error instanceof TimeoutException) {
|
||||
if (callback.thread instanceof Thread) {
|
||||
console.debug(console.stack(callback.thread as any))
|
||||
}
|
||||
return console.warn(`Task ${callback.name || '<anonymous>'} => ${callback} exec time greater than ${this.queueMicrotaskExecuteTimeout}ms!`)
|
||||
}
|
||||
throw error.getCause && error.getCause() || error
|
||||
@@ -146,8 +157,8 @@ class EventLoop {
|
||||
constructor() {
|
||||
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
||||
this.fixedThreadPool = new ThreadPoolExecutor(
|
||||
8, 16, 0, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue(1024),
|
||||
4, 16, 32, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue(32),
|
||||
new ThreadFactory((run: any) => {
|
||||
let thread = new Thread(run, "@ccms/event-loop-" + this.threadCount.incrementAndGet())
|
||||
thread.setDaemon(true)
|
||||
@@ -207,6 +218,7 @@ class EventLoop {
|
||||
try {
|
||||
this.fixedThreadPool.submit(new Callable({
|
||||
call: () => {
|
||||
callback.thread = Thread.currentThread();
|
||||
try {
|
||||
callback.apply(undefined, args)
|
||||
} catch (cause: any) {
|
||||
@@ -225,6 +237,9 @@ class EventLoop {
|
||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
||||
}
|
||||
if (error instanceof TimeoutException) {
|
||||
if (callback.thread instanceof Thread) {
|
||||
console.debug(console.stack(callback.thread as any).join('\n'))
|
||||
}
|
||||
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}ms!`)
|
||||
}
|
||||
throw error.getCause && error.getCause() || error
|
||||
|
||||
Reference in New Issue
Block a user