Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. @Named
  2. @ViewScoped
  3. public class MyManagedBean {
  4.  
  5. @Inject
  6. private ExecutionService executionService;
  7.  
  8. public void executeAsyncTask(Suite suite) {
  9. try {
  10. Future<Boolean> result = executionService.executeStuff(suite);
  11. if (result.isDone()) {
  12. // 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
  13. }
  14. }
  15.  
  16. @Singleton
  17. @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
  18. public class ExecutionService extends BaseBean implements Serializable {
  19. //
  20. @Inject private ExecutionDAO execDao;
  21. //
  22. @Asynchronous
  23. public Future<Boolean> executeStuff(Suite suite) throws BusinessException {
  24.  
  25. Boolean areStiffExecuted = false;
  26.  
  27. Process process;
  28.  
  29. try {
  30. process = Runtime.getRuntime().exec(new String[]{ });
  31. // and other crazy stuff that take some time.
  32. } catch (Exception e) {
  33. // log exception and throw it to managed bean
  34. } finally {
  35. // do some stuff like destroying process
  36. return new AsyncResult<>(true);
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment