I would like to run several long tasks with Spring Boot using a TaskExecutor. I want to have multiple rfid readers running and getting tags of items continuously. Then I need to use these tags to update the database. So far I have not been able to get the tasks running more than one time using Spring Boot. Is this possible?
I'm creating a @Component reader class. When creating I start the listener service and the listener to keep track of the tags. I have the startMessageService and the setReaderConfig methods. The first method I start the message listener service to receive the messages with the tag info from the reader when it comes in. The second method sets up the reader to read autonomously so when the tags go by the reader, the reader sends a message to the listener and I receive the message.
The run method basically keeps the reader going to read when the messages come in. But for some reason the code is not working how I want it to. As soon as the reader has a tag come by I should receive a message and I'm not.
At the bottom is my threadpooltaskexecutor bean.
I'm not sure what I'm missing.
@Component
@Scope("prototype")
public class AlienReader extends AlienClass1Reader implements
TagTableListener, MessageListener, Runnable{
private String ipaddress;
private int port;
private String username;
private String password;
int serviceport;
public AlienReader(String ipaddress, int port, String username, String pwd,
int serviceport) throws UnknownHostException, AlienReaderException,
InterruptedException{
super(ipaddress, port);
this.ipaddress=ipaddress;
this.port=port;
this.username=username;
this.password=pwd;
this.serviceport=serviceport;
startMessageService();
setReaderConfig();
}
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(15);
executor.setMaxPoolSize(42);
executor.setQueueCapacity(11);
executor.setThreadNamePrefix("threadPoolExecutor-");
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.initialize();
return executor;
}