java - Implements Runnable over Extends Thread with EJB -



java - Implements Runnable over Extends Thread with EJB -

let's class mycoolprocess has logic of app needed called in it's own thread. we'll create thread, phone call , go on application. class ejb; annotated @stateless

now have mycontroller class; going phone call new thread.

code:

public class mycontroller { @ejb mycoolprocess p; public response foo() { thread t = new thread() { public void run() { p.run(); } }; t.start(); // continues ... } } @stateless public class mycoolprocess { public void run() { // heavy task } }

that working fine; point is... before solution i've tried runnable interface. wanted @ first time. approach be:

public class mycontroller { @ejb mycoolprocess p; public response foo() { thread t = new thread(p); t.start(); // continues ... } } @stateless public class mycoolprocess implements runnable { @override public void run() { // heavy task } }

that doesn't work. actually, server cannot start. crashes trying inject dependencies. i'm not able implement interface runnable if i'm ejb isn't it? why

and... there way runnable way instead anonymous class?

from ejb spec:

the enterprise bean must not effort manage threads. enterprise bean must not effort start, stop, suspend, or resume thread, or alter thread’s priority or name. enterprise bean must not effort manage thread groups.

see adam's blog.

java asynchronous ejb code-injection runnable

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -