Jboss Java EE container and an ExecutorService

后端 未结 5 1780
滥情空心
滥情空心 2020-11-29 01:53

I have a standalone java app which used the ExecutorService to process a number of jobs in parallel

 ExecutorService es = Executors.newFixedThreadPool(10);
<         


        
5条回答
  •  伪装坚强ぢ
    2020-11-29 02:27

    Well... David's solution did not work for me for the following reasons:

    1. Compiler was bitching around that java.util.concurrent is not allowed... which kinda makes sense in JBOSS scope.
    2. Also: public STATIC class...? Read this up: Why are you not able to declare a class as static in Java?

    Here's what I did:
    My installation:
    - JBOSS AS 7.1.1
    - Java 1.6
    - RHEL
    - Running the example with Gradle and Arquillian:

    @Stateless
    public class ExecutorBean {
        @Asynchronous
        public void execute(Runnable command) {
            command.run();    
        }
    }
    

    Then your client looks like this:

    @EJB ExecutorBean eb;
    @Test
    public void testExecutorBean() {
        eb.execute(new YourCustomizedRunnableWhichDoesALotOfUsefulStuff());
        assertFalse(!true);
    }
    

    Beware, though: In my standalone.xml (or generally speaking my config file for JBOSS I have a section 'thread-pools'. Have a look at it (if you happen to use JBOSSAS) and tinker with the values there. Find out how it behaves. When I use threads with arquillian tests I get threads that are killed though my keepalive-time is very high. I think this has to do with how arquillian microdeploys. When arquillian finishes all non-finished threads are killed which were running whilst the tests are being run... at least that is what I think I observe. On the other hand all finished threads actually behaved well in that sense that they completed their tasks/operations.

    Hope this post helps!

提交回复
热议问题