Victor Mezrin
Victor Mezrin

Reputation: 2847

concurrent threads for a method of EJB

I have a stateless EJB with method that process data. Usually method works 5..20 seconds

I need to have about 10 threads, that executes that method concurrently. So I made annotation for that method @Schedule(second = "*", minute = "*", hour = "*") But container (Glassfish 4) launches only one thread for my method.

I tried to use annotation @Asynchronous, but it make no effect

What should I do?

Upvotes: 0

Views: 150

Answers (1)

Smutje
Smutje

Reputation: 18143

Write a second class using the @Schedule(second = "*", minute = "*", hour = "*") to call your @Asynchronous EJB method - then, if the duration is as you said, it should start a new thread every second.

Minimal Example

Caller.java

public class Caller {

    @EJB
    AsyncEJB asyncEjb;       

    @Schedule(second = "*", minute = "*", hour = "*")
    public void call() {
        this.asyncEjb.call(); 
    }
}

AsyncEJB.java

@Stateless
public class AsyncEJB {

    @Asynchronous
    public void call() {
        // Do long running stuff.
    }
}

Upvotes: 2

Related Questions