LiteFlow LiteFlow
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • 🍤Introduction
  • 🍓Features
  • 🍟Quick Start(Hello world)

    • 🍄Notice
    • 🌿Springboot environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌱Spring environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌵Other environment

      • 🍄Notice
      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
  • 🍢Configuration item

    • 🍄Notice
    • 🌿Springboot environment
    • 🌱Spring environment
    • 🌵Other environment
  • 🗂Rules file

    • 📔Rules file format
    • 📕Local rule file
    • 📗Zookeeper source
    • 📘SQL database source
    • 📋Nacos source
    • 🗄Etcd source
    • 📙Custom source
  • 🔗General components

    • 📎Common component
    • ✂️Switch component
    • 📌If component
    • 🧬For component
    • ⛓While component
    • 🧿Break component
  • 🧩How to write EL rules

    • 🍄Notice
    • 🌴Serial mode
    • 🎋Parallel mode
    • 🌾Switch mode
    • 🌵If mode
    • 🌳Loop mode
    • 🍁Use sub chain
    • 🍂Use sub variables
    • 💐Complex example
    • 🌻About semicolons
    • 🌰About comments
    • 🐚Component Name Package
  • 🌮Data context

    • 🍄Notice
    • 🌯Definition and use
    • 🪶Pass initialized context
  • 🛩Flow executor

    • 🍄Notice
    • 🎡Executor method
    • 🎢Chain input parameter
    • 🎈LiteflowResponse object
  • 🍋Script component

    • 🍫Choose a script language
    • 🍕Define script component
    • 🌯Define file script
    • 🍣Interact with java
    • 🍘Dynamic refresh script
  • 🍇Declarative component

    • 🥭What is a declarative component
    • 🧅Class level declaration
    • 🥥Method level declaration
  • 🎲Dynamic rules

    • 🍄Notice
    • 🎯How to build
  • 🎨Advanced features

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
    • 🥑Implicit chain
    • 🍕Private delivery
    • 🍣Component retry
    • 🍖Smooth hot refresh
    • 🍪Component aspect
    • 🍡Step information
    • 🧊Exceptions
    • 🧇Printing details
    • 🧁Custom request id
    • 🌭Multiple type rules
    • 🥗Asynchronous thread pool
      • Default global thread pool
      • Custom global thread pool
      • Thread pool for WHEN
      • Priority
    • 🍿Custom component executor
    • 🍥Simple monitor
    • 🧉DTD in Xml
  • ⛱Test cases and demo

    • 🪁Test cases
    • 🪀Demo
  • 🪂Performance
  • v2.9.X文档
  • 🎨Advanced features
铂赛东
2022-07-03
Contents

🥗Asynchronous thread pool

# Default global thread pool

LiteFlow has a global thread pool by default, and parameters such as the size of the thread pool can be set by setting the following parameters:

liteflow.when-max-wait-seconds=15
liteflow.when-max-workers=16
liteflow.when-queue-limit=512

# Custom global thread pool

But if you have special requirements for thread pools, LiteFlow also supports custom thread pool settings.

It should be noted that the custom thread pool is only applicable to parallel components, this parameter has no effect on synchronous components. And once you set your custom thread pool, the above parameters will no longer be useful. The definition of all parameters of the thread pool is up to you.

First you can define a thread pool Builder like this:

public class CustomThreadBuilder implements ExecutorBuilder {
    @Override
    public ExecutorService buildExecutor() {
        return Executors.newCachedThreadPool();
    }
}

Then add your Builder to the LiteFlow configuration. For springboot, you can configure it like this:

liteflow.thread-executor-class=com.yomahub.liteflow.test.customThreadPool.CustomThreadBuilder

If it is in spring, you can configure it like this:

<bean id="liteflowConfig" class="com.yomahub.liteflow.property.LiteflowConfig">
	<property name="ruleSource" value="customThreadPool/flow.el.xml"/>
    <property name="threadExecutorClass" value="com.yomahub.liteflow.test.customThreadPool.CustomThreadExecutor"/>
</bean>

<bean id="flowExecutor" class="com.yomahub.liteflow.core.FlowExecutor">
  <property name="liteflowConfig" ref="liteflowConfig"/>
</bean>

In this way, LiteFlow will automatically load the custom thread pool through the Builder you declare when it starts.

# Thread pool for WHEN

In some scenarios, your asynchronous nodes may not need a global thread pool, and you want to set a separate thread pool for each group of asynchronous nodes.

For example, I now want to set up different thread pools for the following two chains:

<chain name="chain1">
    WHEN(a, b);
</chain>

<chain name="chain2">
    WHEN(c, d);
</chain>

First implement 2 own thread pools:

public class CustomThreadExecutor1 implements ExecutorBuilder {

    @Override
    public ExecutorService buildExecutor() {
        //Construct your custom thread pool
    }
}
public class CustomThreadExecutor2 implements ExecutorBuilder {

    @Override
    public ExecutorService buildExecutor() {
        //Construct your custom thread pool
    }
}

Then you declare it as follows:

<chain name="chain1">
    WHEN(a, b).threadPool("com.yomahub.liteflow.test.customWhenThreadPool.CustomThreadExecutor1");
</chain>
<chain name="chain2">
    WHEN(c, d).threadPool("com.yomahub.liteflow.test.customWhenThreadPool.CustomThreadExecutor2");
</chain>

# Priority

If both the global and WHEN are configured with a custom thread pool, the thread pool configured on WHEN is used first.

Help us improve this document (opens new window)
last update: 2022/11/30, 22:42:09
🌭Multiple type rules
🍿Custom component executor

← 🌭Multiple type rules 🍿Custom component executor→

Theme by Vdoing | Copyright © 2020-2022 铂赛东 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式