Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: Sebastian Newsgroups: comp.lang.java.programmer Subject: Re: Exception Handling in Asynchronous Java Code Date: Wed, 30 Jul 2014 17:43:48 +0200 Organization: albasani.net Lines: 36 Message-ID: References: <2e594246-2475-4b45-ae5e-2624b9a843d1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net T6uh53NBQKgFANIwNOaSQgtR0wnWFfJ3Gw1terOCjGiLP4r5FaIWbuH+2jw7u1X1fyE73FPnj3X2t5uJHyRRRw== NNTP-Posting-Date: Wed, 30 Jul 2014 15:43:49 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="k1n3s7pM4inOisHEtcftKg9Wto4ouN4NjXvk9/ijZmyPmemECN9ALoi1VFftrWOOVgJw4Rzt/HIx8nPAUHPmzkuEwQtPVNpDZVSvrlEujxET1zI7t5MRwnvss33et+c/"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: <2e594246-2475-4b45-ae5e-2624b9a843d1@googlegroups.com> Cancel-Lock: sha1:UXLh+lrldjqQ/6W3joCkdmQ5pUw= Xref: csiph.com comp.lang.java.programmer:29443 Am 30.07.2014 15:49, schrieb valerio.celletti@lightstreamer.com: > Hi All, > > Long time lurker, first time poster. I'd like to point your attention on an article we recently published on our company blog, titled "Exception Handling in Asynchronous Java Code" (link: http://blog.lightstreamer.com/2014/07/exception-handling-in-asynchronous-java.html). > > The article explains how to obtain the typical benefits of hierarchical exception handling and static exception checking even for event-driven programming or asynchronous programming. This can be achieved by writing code that follows a specific pattern and leans on a suitable support library. The same technique was applied in some parts of Lightstreamer (which is a real-time data streaming server written in Java) with proficiency. > > I'd like to hear your thoughts and feedbacks on above. What do you think? > > Thanks and regards, > Valerio > Very nice exposition. I'd like to add that with the advent of Java 8 there is a base for such frameworks already provided with the JDK, so it may be possible to get rid of much of the complexity of your current implementation. Java 8 contains java.util.concurrent.CompletableFuture, a new class that represents a CompletionStage of a possibly asynchronous computation and provides many ways to bind some function to the result of an existing computation. The asynchronous chaining methods will use the common ForkJoin pool, otherwise you may provide an executor of your choice. Especially relevant with regard to the point of your presentation is the ability of CompletableFuture to completeExceptionally(), throwing an exception when the result of the computation is retrieved from the future. -- Sebastian PS: Here's a good intro to CompletableFuture: http://www.nurkiewicz.com/2013/05/java-8-definitive-guide-to.html