tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TOMEE-2301) Concurrency utilities example
Date Fri, 30 Nov 2018 17:20:00 GMT

    [ https://issues.apache.org/jira/browse/TOMEE-2301?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16705041#comment-16705041
] 

ASF GitHub Bot commented on TOMEE-2301:
---------------------------------------

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!


> Concurrency utilities example
> -----------------------------
>
>                 Key: TOMEE-2301
>                 URL: https://issues.apache.org/jira/browse/TOMEE-2301
>             Project: TomEE
>          Issue Type: Improvement
>          Components: Examples and Documentation
>    Affects Versions: 8.0.0-Final
>            Reporter: Bruno Baptista
>            Priority: Major
>              Labels: concurrency, examples, pull-request-available
>
> This is an example to demontrate the Concurrency Utilities introduced in JEE7:
> [https://docs.oracle.com/javaee/7/tutorial/concurrency-utilities.htm#top]
> It will use CompletableFutures.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message