Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Named
- @ViewScoped
- public class MyManagedBean {
- @Inject
- private ExecutionService executionService;
- public void executeAsyncTask(Suite suite) {
- try {
- Future<Boolean> result = executionService.executeStuff(suite);
- if (result.isDone()) {
- // send a redirect if he is in the same page of the button that calls this method. It doesn't work, it's result is always false because execution is not finished and method moves on with his life
- }
- }
- @Singleton
- @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
- public class ExecutionService extends BaseBean implements Serializable {
- //
- @Inject private ExecutionDAO execDao;
- //
- @Asynchronous
- public Future<Boolean> executeStuff(Suite suite) throws BusinessException {
- Boolean areStiffExecuted = false;
- Process process;
- try {
- process = Runtime.getRuntime().exec(new String[]{ });
- // and other crazy stuff that take some time.
- } catch (Exception e) {
- // log exception and throw it to managed bean
- } finally {
- // do some stuff like destroying process
- return new AsyncResult<>(true);
- }
- }
- }
Add Comment
Please, Sign In to add comment