I've annotated a Thread class as follow:
@Transactional(propagation = Propagation.REQUIRED)
@Component
@Scope("prototype")
public class ThreadRetrieveStockInfoEuronext implements Runnable {
...
}
The Thread is wired into a Controller class, and called via Global.poolMultiple.execute(threadRetrieveStockInfoEuronext);
public class RetrievelController {
@Autowired
private ThreadRetrieveStockInfoEuronext threadRetrieveStockInfoEuronext;
@RequestMapping(value = "/.retrieveStockInfo.htm", method = RequestMethod.POST)
public ModelAndView submitRetrieveStockInfo(@ModelAttribute("retrieveStockInfoCommand") RetrieveStockInfoCommand command, BindingResult result, HttpServletRequest request) throws Exception {
Global.poolMultiple.execute(threadRetrieveStockInfoEuronext);
return new ModelAndView(".retrieveStockInfo", "retrieveStockInfoCommand", command);
}
The Global Class:
@SuppressWarnings("unchecked")
@Component
public class Global {
// create ExecutorService to manage threads
public static ExecutorService poolMultiple = Executors.newFixedThreadPool(10);
public static ExecutorService poolSingle = Executors.newFixedThreadPool(1);
...
}
When running the application, the following exception occurs:
java.lang.IllegalArgumentException: Can not set com.chartinvest.admin.thread.ThreadRetrieveStockInfoEuronext field
com.chartinvest.controller.RetrievelController.threadRetrieveStockInfoEuronext to com.sun.proxy.$Proxy52