Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inject an EJB into a Runnable  RSS feed

 
Antonio Foglia
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does exist a method for inject an ejb into a Runnable? First time i've tried to make my Runnable class "@Stateless" and then inject through "@EJB", then i've tried with the context lookup

public class Pusher implements Runnable{
public Pusher(){
}
@Override
public void run() {
InitialContext ctx;
try {
ctx = new InitialContext();
VehicleStatusLocal vehicleS = (VehicleStatusLocal) ctx.lookup("statusBean");
//launch ejb method
vehicleS.update();
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i know that the right way is to inject a bean inside the EJB context. But i have to update some data from a non-EJB class.

Thanks
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Injection is only supported in container managed classes. Random classes like an implementation of Runnable do not have Java EE injection support. Plain JNDI lookup is your alternative to such cases.
 
Antonio Foglia
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:Injection is only supported in container managed classes. Random classes like an implementation of Runnable do not have Java EE injection support. Plain JNDI lookup is your alternative to such cases.

Ok but it seems no good for my application. I need to explain better
here's another question with the general scenario

http://www.coderanch.com/t/631528/EJB-JEE/java/Mqtt-Client-JEE-application-JBoss#2891891
 
Luan Cestari
Ranch Hand
Posts: 172
C++ Redhat Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Antonio Foglia wrote:
Jaikiran Pai wrote:Injection is only supported in container managed classes. Random classes like an implementation of Runnable do not have Java EE injection support. Plain JNDI lookup is your alternative to such cases.

Ok but it seems no good for my application. I need to explain better
here's another question with the general scenario

http://www.coderanch.com/t/631528/EJB-JEE/java/Mqtt-Client-JEE-application-JBoss#2891891


The context lookup should handle this task, some application server may implement thos calls to be handle almost like local invocations (in case in the same JVM) so it would spend less resource. Did it work for yo?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!