Java 使用EnableSync的Spring引导队列导致内存已满

Java 使用EnableSync的Spring引导队列导致内存已满,java,spring-boot,queue,Java,Spring Boot,Queue,我目前正在创建一个使用双队列的应用程序。不幸的是,该应用程序似乎导致内存已满并被操作系统杀死 我想做的是像这样排队 测试1->测试2->测试3 test1按计划运行,将test2排队,然后test2处理队列,将test3排队,最后是test3处理。test2和test3之间的队列使用相对较大的字符串str 当我运行它几次时,它就像我预期的那样工作。如果我运行test1 1000次,内存使用量将不断增加而不会减少,这会导致应用程序因内存使用过多而被操作系统杀死。 似乎Java不会删除该对象,尽管它

我目前正在创建一个使用双队列的应用程序。不幸的是,该应用程序似乎导致内存已满并被操作系统杀死

我想做的是像这样排队

测试1->测试2->测试3

test1按计划运行,将test2排队,然后test2处理队列,将test3排队,最后是test3处理。test2和test3之间的队列使用相对较大的字符串str

当我运行它几次时,它就像我预期的那样工作。如果我运行test1 1000次,内存使用量将不断增加而不会减少,这会导致应用程序因内存使用过多而被操作系统杀死。 似乎Java不会删除该对象,尽管它不再被使用

我是新使用Spring Boot的,但找不到解决方案

你能给我一些建议吗

第一类是:

第二类是:

第三节课是

下面是主类中bean的定义,我只使用一个线程进行排队:

@Component
public Class Test1{

    @Autowired
    private Test2 test2;

    @Scheduled(fixedRateString = "${scheduler.fixed-rate}")
    public void test1() {
    
        void method() {
            int val = ...;
            test2.execTest2(val);
        }
    }
}
@Component
public Class Test2{

    @Autowired
    private Test3 test3;

    @Async("Thread_Test2")
    public void execTest2(int val){
        //heavy tasks
        String str = ...;
        test3.execTest3(str);
    }
}
@Component
public Class Test3{

    @Async("Thread_Test3")
    public void execTest3(String str){
        //heavy tasks
    }
}
@EnableScheduling
@SpringBootApplication
@EnableAsync
public class Main {

    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }

    @Bean("Thread_Test2")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(1);
        executor.setMaxPoolSize(1);
        executor.setQueueCapacity(Integer.MAX_VALUE);
        executor.initialize();
        return executor;  
    }

    @Bean("Thread_Test3")
    public Executor taskExecutor2() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(1);
        executor.setMaxPoolSize(1);
        executor.setQueueCapacity(Integer.MAX_VALUE);
        executor.initialize();
        return executor;
    }
}