使Springboot @service类方法一次仅通过一个线程访问

发布于 2025-02-09 13:59:51 字数 539 浏览 1 评论 0原文

我需要使我的@Service类方法一次只能访问一个线程。由于该方法调用@Autowied另一个实例,我无法将静态同步关键字添加到该方法中。

请就此建议。

谢谢。

在此处添加了示例Java类,

@Service
public class Saver implements DataSaver {

    @Autowired
    private SaverLogic saverLogic;
    
    
    @Override
    public String process(...) {
        Future<String> result = saverLogic.save(repositoryContainer, entities);

    }

我需要制作Process()方法静态同步,但是由于自动实例,我无法执行此操作。 SaverLogic类包含@ASYNC方法。

请帮助我。

I need to make my @service class a method can be access only one thread at a time. I can't add static synchronized keywords to the method due to that method call @Autowired another instances.

Please advice on this.

Thank you.

Added sample java class here,

@Service
public class Saver implements DataSaver {

    @Autowired
    private SaverLogic saverLogic;
    
    
    @Override
    public String process(...) {
        Future<String> result = saverLogic.save(repositoryContainer, entities);

    }

I need to make process() method static synchronized but due to autowired instance I can't do this. SaverLogic class contains a @Async method.

Please help me on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文