[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
GitHub user brunobat opened a pull request:

    https://github.com/apache/tomee/pull/223

    TOMEE-2301 - Concurrency utilities example

   

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/brunobat/tomee executor-example

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/tomee/pull/223.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #223
   
----
commit 5229a81313ff31ee50b132895a95ab302c37628f
Author: brunobat <brunobat@...>
Date:   2018-11-29T12:21:07Z

    TOMEE-2301 - project creation
   
    Signed-off-by: brunobat <[hidden email]>

commit 632ee2c319fc6d261bd948e6970dacc98e877aea
Author: brunobat <brunobat@...>
Date:   2018-11-29T12:21:19Z

    TOMEE-2301 - Creation on 3 test: normal path, timeout, ended with exception
   
    Signed-off-by: brunobat <[hidden email]>
   
    rename project
   
    Signed-off-by: brunobat <[hidden email]>
   
    perform first example
   
    Signed-off-by: brunobat <[hidden email]>
   
    Add example with exception handling and refactor
   
    Signed-off-by: brunobat <[hidden email]>

----


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee issue #223: TOMEE-2301 - Concurrency utilities example

mpredli01
Github user brunobat commented on the issue:

    https://github.com/apache/tomee/pull/223
 
    This is still a work in progress


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user cesarhernandezgt commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r237923335
 
    --- Diff: examples/concurrency-utils/src/main/java/org/superbiz/executor/ManagedService.java ---
    @@ -0,0 +1,89 @@
    +package org.superbiz.executor;
    +
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + * <p>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p>
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +import javax.annotation.Resource;
    +import javax.enterprise.concurrent.ManagedExecutorService;
    +import javax.enterprise.context.RequestScoped;
    +import java.util.concurrent.CompletableFuture;
    +import java.util.function.Supplier;
    +
    +import static java.util.Objects.nonNull;
    +
    +
    +@RequestScoped
    +public class ManagedService {
    +
    +    @Resource
    +    private ManagedExecutorService executor;
    +
    +    /**
    +     * Executes an opperation asynchronously, in a different thread provided by the {@link ManagedExecutorService}.
    +     * The computation will carry on after the return of the method.
    +     *
    +     * @param value The demo data.
    +     * @return A {@link CompletableFuture} that will return immediately.
    +     */
    +    public CompletableFuture<Integer> asyncTask(final int value) {
    +        return CompletableFuture
    +                .supplyAsync(delayedTask(value, 100, null), executor) // Execute asynchronously.
    +                .thenApply(i -> i + 1); // After the return of the task, do something else with the result.
    +    }
    +
    +    /**
    +     * Executes an opperation asynchronously, in a different thread provided by the {@link ManagedExecutorService}.
    +     * The computation will carry on after the return of the method.
    +     *
    +     * @param value The demo data.
    +     * @return A {@link CompletableFuture} that will return immediately.
    +     */
    +    public CompletableFuture<Integer> asyncTaskWithException(final int value) {
    --- End diff --
   
    It would be nice to print also a message like in the asyncTask.
    I also need to perform this on the example I'm running. I think it provides more visibility if the reader executes everything from command line.


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user cesarhernandezgt commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r237923742
 
    --- Diff: examples/concurrency-utils/pom.xml ---
    @@ -0,0 +1,68 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<project xmlns="http://maven.apache.org/POM/4.0.0"
    +         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    +         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <groupId>org.superbiz</groupId>
    +    <artifactId>concurrency-utils</artifactId>
    --- End diff --
   
    Does concurrency-utils actually involve future?
    When I read concurrency I think in something like this: https://docs.oracle.com/javase/tutorial/essential/concurrency/index.html
   
    My 2 cents fro the name:  asynch-utils


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user brunobat commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r237937619
 
    --- Diff: examples/concurrency-utils/src/main/java/org/superbiz/executor/ManagedService.java ---
    @@ -0,0 +1,89 @@
    +package org.superbiz.executor;
    +
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + * <p>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p>
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +import javax.annotation.Resource;
    +import javax.enterprise.concurrent.ManagedExecutorService;
    +import javax.enterprise.context.RequestScoped;
    +import java.util.concurrent.CompletableFuture;
    +import java.util.function.Supplier;
    +
    +import static java.util.Objects.nonNull;
    +
    +
    +@RequestScoped
    +public class ManagedService {
    +
    +    @Resource
    +    private ManagedExecutorService executor;
    +
    +    /**
    +     * Executes an opperation asynchronously, in a different thread provided by the {@link ManagedExecutorService}.
    +     * The computation will carry on after the return of the method.
    +     *
    +     * @param value The demo data.
    +     * @return A {@link CompletableFuture} that will return immediately.
    +     */
    +    public CompletableFuture<Integer> asyncTask(final int value) {
    +        return CompletableFuture
    +                .supplyAsync(delayedTask(value, 100, null), executor) // Execute asynchronously.
    +                .thenApply(i -> i + 1); // After the return of the task, do something else with the result.
    +    }
    +
    +    /**
    +     * Executes an opperation asynchronously, in a different thread provided by the {@link ManagedExecutorService}.
    +     * The computation will carry on after the return of the method.
    +     *
    +     * @param value The demo data.
    +     * @return A {@link CompletableFuture} that will return immediately.
    +     */
    +    public CompletableFuture<Integer> asyncTaskWithException(final int value) {
    --- End diff --
   
    Will do, it's a good tip. Thanks!


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user brunobat commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r237940616
 
    --- Diff: examples/concurrency-utils/pom.xml ---
    @@ -0,0 +1,68 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<project xmlns="http://maven.apache.org/POM/4.0.0"
    +         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    +         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <groupId>org.superbiz</groupId>
    +    <artifactId>concurrency-utils</artifactId>
    --- End diff --
   
    It's related to the JEE concurrency utilities. A complement to the SE version that you mention. See: https://docs.oracle.com/javaee/7/tutorial/concurrency-utilities002.htm#CIHFBCFH
   
    They provide managed executors for runnable, etc. They were created to address the fact that you should not start your own threads inside a container. These utilities basically manage the threads lifecycle for you.
    And yes, they use Future. I'm using CompletableFutures, which itself implements Future because it's more powerful and less known. This way we get a double advantage with the example.
   
    I'll probably take some time to explain all this and provide more context in the Readme.


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee issue #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user ivanjunckes commented on the issue:

    https://github.com/apache/tomee/pull/223
 
    Hey @brunobat, tried  to build the project here but got a maven failure. I am using 3.5 and the project in enforcing 3.7.
   
    You should follow the maven.version established in the project.
    https://github.com/apache/tomee/blob/3f07dc964577b52a177173b6cfafbae5aa85adc0/pom.xml#L147


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user ivanjunckes commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r237984715
 
    --- Diff: examples/concurrency-utils/pom.xml ---
    @@ -0,0 +1,68 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<project xmlns="http://maven.apache.org/POM/4.0.0"
    +         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    +         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <groupId>org.superbiz</groupId>
    +    <artifactId>concurrency-utils</artifactId>
    +    <version>8.0.0-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>OpenEJB :: Examples :: Concurrency utilities example</name>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +        <javaee-api.version>8.0</javaee-api.version>
    +        <junit.version>4.12</junit.version>
    +    </properties>
    +
    +    <dependencies>
    +        <dependency>
    +            <groupId>org.apache.tomee</groupId>
    +            <artifactId>javaee-api</artifactId>
    +            <version>${javaee-api.version}</version>
    +            <scope>provided</scope>
    +        </dependency>
    +        <!--Tests-->
    +        <dependency>
    +            <groupId>junit</groupId>
    +            <artifactId>junit</artifactId>
    +            <version>${junit.version}</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.tomee</groupId>
    +            <artifactId>arquillian-tomee-remote</artifactId>
    +            <version>${pom.version}</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.jboss.arquillian.junit</groupId>
    +            <artifactId>arquillian-junit-container</artifactId>
    +            <version>1.4.0.Final</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.jboss.arquillian.container</groupId>
    +            <artifactId>arquillian-container-test-api</artifactId>
    +            <version>1.4.0.Final</version>
    +            <scope>test</scope>
    +        </dependency>
    +    </dependencies>
    +
    +    <build>
    --- End diff --
   
    This is not needed. Add this to the pom file:
     <parent>
            <artifactId>examples</artifactId>
            <groupId>org.apache.tomee</groupId>
            <version>8.0.0-SNAPSHOT</version>
        </parent>


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user brunobat commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r238332043
 
    --- Diff: examples/concurrency-utils/pom.xml ---
    @@ -0,0 +1,68 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<project xmlns="http://maven.apache.org/POM/4.0.0"
    +         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    +         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <groupId>org.superbiz</groupId>
    +    <artifactId>concurrency-utils</artifactId>
    +    <version>8.0.0-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>OpenEJB :: Examples :: Concurrency utilities example</name>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +        <javaee-api.version>8.0</javaee-api.version>
    +        <junit.version>4.12</junit.version>
    +    </properties>
    +
    +    <dependencies>
    +        <dependency>
    +            <groupId>org.apache.tomee</groupId>
    +            <artifactId>javaee-api</artifactId>
    +            <version>${javaee-api.version}</version>
    +            <scope>provided</scope>
    +        </dependency>
    +        <!--Tests-->
    +        <dependency>
    +            <groupId>junit</groupId>
    +            <artifactId>junit</artifactId>
    +            <version>${junit.version}</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.tomee</groupId>
    +            <artifactId>arquillian-tomee-remote</artifactId>
    +            <version>${pom.version}</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.jboss.arquillian.junit</groupId>
    +            <artifactId>arquillian-junit-container</artifactId>
    +            <version>1.4.0.Final</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.jboss.arquillian.container</groupId>
    +            <artifactId>arquillian-container-test-api</artifactId>
    +            <version>1.4.0.Final</version>
    +            <scope>test</scope>
    +        </dependency>
    +    </dependencies>
    +
    +    <build>
    --- End diff --
   
    Sorry @ivanjunckes what part is not needed?



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user ivanjunckes commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/223#discussion_r238347975
 
    --- Diff: examples/concurrency-utils/pom.xml ---
    @@ -0,0 +1,68 @@
    +<?xml version="1.0" encoding="UTF-8"?>
    +<project xmlns="http://maven.apache.org/POM/4.0.0"
    +         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    +         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    +
    +    <modelVersion>4.0.0</modelVersion>
    +
    +    <groupId>org.superbiz</groupId>
    +    <artifactId>concurrency-utils</artifactId>
    +    <version>8.0.0-SNAPSHOT</version>
    +    <packaging>jar</packaging>
    +    <name>OpenEJB :: Examples :: Concurrency utilities example</name>
    +
    +    <properties>
    +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    +        <javaee-api.version>8.0</javaee-api.version>
    +        <junit.version>4.12</junit.version>
    +    </properties>
    +
    +    <dependencies>
    +        <dependency>
    +            <groupId>org.apache.tomee</groupId>
    +            <artifactId>javaee-api</artifactId>
    +            <version>${javaee-api.version}</version>
    +            <scope>provided</scope>
    +        </dependency>
    +        <!--Tests-->
    +        <dependency>
    +            <groupId>junit</groupId>
    +            <artifactId>junit</artifactId>
    +            <version>${junit.version}</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.apache.tomee</groupId>
    +            <artifactId>arquillian-tomee-remote</artifactId>
    +            <version>${pom.version}</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.jboss.arquillian.junit</groupId>
    +            <artifactId>arquillian-junit-container</artifactId>
    +            <version>1.4.0.Final</version>
    +            <scope>test</scope>
    +        </dependency>
    +        <dependency>
    +            <groupId>org.jboss.arquillian.container</groupId>
    +            <artifactId>arquillian-container-test-api</artifactId>
    +            <version>1.4.0.Final</version>
    +            <scope>test</scope>
    +        </dependency>
    +    </dependencies>
    +
    +    <build>
    --- End diff --
   
    maven-compiler-plugin, just add the xml for the parent.


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee issue #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user jeanouii commented on the issue:

    https://github.com/apache/tomee/pull/223
 
    Hi all,
   
    How are we looking on this one?
    Is it ready to go?


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee issue #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user brunobat commented on the issue:

    https://github.com/apache/tomee/pull/223
 
    Hi @jeanouii  
    I'm still working on some additional examples.
    Will send an email to the list when ready.


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] tomee pull request #223: TOMEE-2301 - Concurrency utilities example

mpredli01
In reply to this post by mpredli01
Github user asfgit closed the pull request at:

    https://github.com/apache/tomee/pull/223


---