나는 Seam을 처음 접했을 때 의존성 삽입물에 약간의 문제가 있습니다. 잘못된 방식으로 뭔가를하고있을 수도 있습니다!내 컨트롤러에서 새 스레드에 @In (jboss seam 사용)의 종속성을 주입 할 수없는 이유는 무엇입니까?
컨트롤러에서 해고 된 새 스레드에 종속성을 주입해야합니다. 예외는 없지만 간단히 null
이됩니다. 먼저 스레드 내에서 d1
(아래 참조)을 재사용하려고했지만 그때는 null
이었습니다.이 아이디어를 가지고이 객체에 다시 주석을 달았습니다 @In
... 불행히도 같은 일이 발생했습니다.
@Scope(ScopeType.CONVERSATION)
@Name("myController")
public class MyController{
@In(create = true)
private Dependency1 d1; //ok, gets injected with no problems!
public void importantMethod(){
//this part of the method is important and is fast
//but below comes an expensive part that takes some minutes
new Thread(new Runnable(){
@In(create = true)
private Dependency1 anotherD1; //I still need d1 here!!!
@Override
public void run(){
//I want to run expensive code here.
//A new thread is required in order to leave
//the visitor free to go else where on the web site
//First trial was to make d1 final and simply use it here!
//d1.doExpensiveStuff();
};
}).start();
}
}
왜 이런 일이 일어나는 지 아는 사람이 있습니까? DI/Seam/Threading으로 작업 할 때 좋은 연습이 있습니까?