Currently i am troubling that how to get data from database inside my thread class.
I can't make bean of my thread class because new instance is created of thread on every request.
MyThread.class
class MyThread implements Runnable{
public void run(){
//How to get Employee data and also data from other tables.??????
}
}
EmployeeDAO.class
@Component("employeeDAO")
public class EmployeeDAO {
@Cacheable(value = "employeeCache")
public List<Employee> getEmployees() {
//got data from database
return employees;
}
}
Is this good to get context and get dao bean from context and use in every my thread class?
Can you suggest or share code how to solve my above problem?
I have found one solution from this site .
Is below solution is good or not? If not good then what are disadvantage of solution
Here is what I tried and got success