• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inject an EJB into a Runnable

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

https://coderanch.com/t/631528/EJB-JEE/java/Mqtt-Client-JEE-application-JBoss#2891891
 
Ranch Hand
Posts: 172
Redhat Ruby C++
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

https://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?
reply
    Bookmark Topic Watch Topic
  • New Topic