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
Post a Comment