EJB3 timeout processing without threading

I have the following situation. I have a job that:

  • It may expire after a certain amount of time, and if this happens, an exception must be thrown.
  • If this is not a timeout, will return the result.
  • If this task returns a result, it should be returned as quickly as possible, because performance is very important. Thus, asynchronous solutions are excluded from the table, and, of course, binding the system by clogging is also not an option.
  • Finally, the system must comply with the EJB standard, so AFAIK using regular streams is not an option, since it is strictly prohibited.

Our current solution uses a thread that will throw an exception after it has existed for a certain time, without interruption by an external process, but since this clearly violates the EJB standard, we are trying to solve it using some other means.

Any ideas?

Edited to add: Naturally, a task that has a timeout must be deleted (or interrupted).

Edited for Appendix 2: This problem does not seem to have any solution, because detecting a deadlock seems to be impossible in most cases to adhere to pure EJB3 standards. Since Enno Shioji's comments below reflect this, I ask his assumption as the correct answer.

+4
source share
6

, , .

, , , , , , . :

//Some webservice method (synchronous)
public Result process(Blah blah){
    try{
        return getResult(TimeUnit.SECONDS, 10);
    }catch(InterruptedException e){
        //No result within 10 seconds!
        throw new ServiceUnavailableException("blah");
    }
}

, . , getResult , . , , "" , , , , , . , , .

, , ?

, ? , - - ?


, , HashedWheelTimer ... ( ). , , , , singleton EJB. , , . . , . singleton EJB. JBoss. , , JVM, - ( - - ), EJB. , , , , .
+1

Bean - UserTransaction.

, .

void setTransactionTimeout(int seconds) throws SystemException
  • . , .
  • .
  • beans, .
  • EJB, .

.

: .

JBoss: @TransactionTimeout(100).

Weblogic: weblogic-ejb-jar.xml

<transaction-descriptor>
     <trans-timeout-seconds>100</trans-timeout-seconds> 
</transaction-descriptor>

GlassFish: cmt-timeout-in-seconds sun-ejb-jar.xml

+1

, @WebService, WAR, WebService EJB.

WAR , EJB, .

, "", .

+1

commonj WorkManager. , WebSphere Weblogic, , -.

, WorkManager , Java. MDB, " " .

, google commonj 8 -)

IBM Oracle.

. , .

0

EJB " ". @TransactionAttribute bean , , (). , , . , , . .

For more information on container-managed transactions, check out: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Transaction3.html and http://download.oracle.com/javaee/5/tutorial/doc /bncij.html

0
source

You can use @TimeOut. Sort of:

@Stateless
public class TimedBean {

  @Resource
  private TimerService timerService;

  static private AtomicInteger counter = new AtomicInteger(0);
  static private Map<Integer, AtomicBoolean> canIRunStore = new ...;

  public void doSomething() {
    Integer myId = counter.getAndIncrement();
    AtomicBoolean canIRun = new AtomicBoolean(true);
    canIRunStore.put(myId, canIRun);

    timerService.createTimer(1000, 0, myId);

    while (canIRun.get() /* && some other condition */) {
      // do my work ... untill timeout ... 
    }
  }

  @Timeout
  @PermitAll
  public void timeout(Timer timer) {
    Integer expiredId = (Integer) timer.getInfo();
    AtomicBoolean canHeRun = canIRunStore.get(expiredId);
    canIRunStore.remove(expiredId);
    canHeRun.set(false);
  }
}
0
source

All Articles