I am trying to build a callable method, in order to execute it every minute. The problem is that my method needs to use an autowired field, which remains null in the callable task, even though before turning this method into a callable one it worked.
Pieces of code:
List<AccountKey> initialLoadKeys = initialLoadController.startInitialLoad();
for (int i = 0; i < initialLoadKeys.size(); i++) {
try {
FutureTask<Void> task = new FutureTask(new AccountController(initialLoadKeys.get(i)));
ScheduledExecutorService es = Executors.newScheduledThreadPool(1);
es.scheduleAtFixedRate(task, 1,1, TimeUnit.MINUTES);
es.execute(task);
es.shutdown();
} catch (RuntimeException e) {
logger.debug(e);
}
}
public class AccountController implements Callable<Void>{
public AccountController () {
}
private AccountKey accountKey;
public AccountController(AccountKey accountKey) {
this.accountKey= accountKey;
}
private AccountManagerWebClient accountManagerWebClient;
public AccountManagerWebClient getAccountManagerWebClient() {
return accountManagerWebClient;
}
public void setAccountManagerWebClient(AccountManagerWebClient accountManagerWebClient) {
this.accountManagerWebClient = accountManagerWebClient;
}
@Override
@Transactional(value = "clientTransaction", propagation = Propagation.REQUIRES_NEW)
public Void call() throws Exception {
accountManagerWebClient.prepareWebServiceRequest(accountKey);
accountManagerWebClient.callWebService(accountKey);
accountManagerWebClient.obtainAccountManagerObjectFromServiceResponseAndPersist(accountKey);
return null;
}
}
The autowired class which is null is accountManagerWebClient...I tried to add this into the constructor, as I did with accountKey, but it did not work. As I mentioned above, it worked before using Callable, but I really have to make usage of this in order to schedule the execution. Can anyone help ?