Jboss Java EE container and an ExecutorService

后端 未结 5 1783
滥情空心
滥情空心 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:42

    Prior to EE7, you might want to use WorkManager from JSR 237

    http://docs.oracle.com/javaee/1.4/api/javax/resource/spi/work/WorkManager.html

    This spec is currently withdrawn, still some app servers implement it. I use ibm implementation in WebSphere 8.5 - IBM WorkManager. It is fully managed resource, available in administration console. Please note that it is not interface-compatible with Oracle.

    Here is an example for IBM version:

    @Resource(lookup = "wm/default")
    WorkManager workManager;
    
    public void process() {
        try {
            ArrayList workItems = new ArrayList();
            for (int i = 0; i < 100; i++) {
                // submit 100 jobs
                workItems.add(workManager.startWork(new Work() {
                    @Override
                    public void run() {
                        try {
                            System.out.println(Thread.currentThread().getName() + " Running");
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
    
                    @Override
                    public void release() {
                        System.out.println(Thread.currentThread().getName() + " Released");
                    }
                }));
            }
            // wait for all jobs to be done.
            workManager.join(workItems, WorkManager.JOIN_AND, 100000);
        } catch (WorkException e) {
            e.printStackTrace();
        }
    }
    

    Also I am aware of Commonj Workmanager.

提交回复
热议问题