> For the complete documentation index, see [llms.txt](https://ankang.gitbook.io/commons/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ankang.gitbook.io/commons/commons-beans/gong-neng/duo-xian-cheng-chu-li.md).

# 多线程处理

对象拷贝过程中，多个字段的拷贝需要串行处理。如果一个对象中存在多个需要调用远程接口的自定义转换器，在没有开启缓存（或者缓存失效）的情况下，可能会有一定的性能问题。在必要情况下可以通过`BeanUtils.ConcurrencyManager`开启多线程处理模式。

示例代码：

```java
// 开启多线程处理模式，仅对当前拷贝有效
BeanUtils.ConcurrencyManager.setMultiThreadProcessing(true);
// 此次拷贝工作在多线程模式下
BeanUtils.copyProperties(foo, FooDto.class);
```

{% hint style="info" %}
由于多线程环境中无法初始化懒加载对象，因此为了确保使用的安全性，目前仅支持字典数据映射的多线程处理，非字典映射字段仍然是单线程串行处理。
{% endhint %}

{% hint style="info" %}
集合的拷贝仅第一条数据的拷贝使用多线程模式，考虑到字典数据映射一般来说存在缓存，因此后续的拷贝无需使用多线程模式。
{% endhint %}
