From users-return-26511-archive-asf-public=cust-asf.ponee.io@tomee.apache.org Tue Feb 13 10:00:17 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id 3068C180656 for ; Tue, 13 Feb 2018 10:00:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 2078A160C53; Tue, 13 Feb 2018 09:00:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 661AA160C50 for ; Tue, 13 Feb 2018 10:00:16 +0100 (CET) Received: (qmail 9316 invoked by uid 500); 13 Feb 2018 09:00:15 -0000 Mailing-List: contact users-help@tomee.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@tomee.apache.org Delivered-To: mailing list users@tomee.apache.org Received: (qmail 9304 invoked by uid 99); 13 Feb 2018 09:00:14 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Feb 2018 09:00:14 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 231231A0451 for ; Tue, 13 Feb 2018 09:00:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.192 X-Spam-Level: *** X-Spam-Status: No, score=3.192 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id qDir1setxCiG for ; Tue, 13 Feb 2018 09:00:08 +0000 (UTC) Received: from mail-yw0-f173.google.com (mail-yw0-f173.google.com [209.85.161.173]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 719265F3B9 for ; Tue, 13 Feb 2018 09:00:08 +0000 (UTC) Received: by mail-yw0-f173.google.com with SMTP id y186so3924821ywf.7 for ; Tue, 13 Feb 2018 01:00:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=inj0gFis2/maCZd0AueOo+dVphMsvdCee+IdSWB9ugg=; b=rfI/vYEW+3HNVDKsfQhYl7ediDn5qbvdqlyIIponzajXE8euwXLldYPNwinzmRscQ3 9e3LVE3qXp3Z2JXyEYrqj0NqM8ugzeOaIYDvq1hFvkofkszUbl67n7jw6CUy971F4c1z ylCeXvO5VFUVv1mHTiD9UjrNhoORxRTwuEcNkYYDwuMSBY4mt51GyStbjEm7AkKuLwk1 9lRYTm2JoRyqZjqnZ+wMUjI852RCbW8a0b1ROnOxsxb9sWjairGXsovvv8gxS6dWG+PV aATbNr6m3cHgmEJqXzdyR9m8MJI6ruUb23nji82UXapVxdW8jdKed8aTIzrgpmWp7VmY zv2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=inj0gFis2/maCZd0AueOo+dVphMsvdCee+IdSWB9ugg=; b=SZSwgin29SL3HiQBzUGoONr6VSs8I4OWPFLINGoo3ueVVafwwE1sPJwLizimP8m+GO nmPP7ADM10TEzHNVi2TyOfpxwBFu0zZxivXh+72RUR/CebOQMrozeqTHMDT2hEOH4gxM TF5fxVHodNg68L7+wcTJ1LJpk63RnveuxHMFqxRgHp7cm8slgkQJ4SBGTM09AHKNW+CK wxWdCFhwfJ7UFY6HLRdn7yZfeb2JLstf39U0XI18xdrLQExF+Y53b1BTxKUzWg3nb3Rx NDhq45Fe4y8XXoIIA22h6JgLfy6OZOgSkzJSgLpc0AjNuRDG2ZyWYI7NFQABm3cLkuMK xReg== X-Gm-Message-State: APf1xPD1+fKrLsQEtQST7ODaCtbGqImS9K3UXpfeKo+tzTtEwelPgQ7r Sx5FXq4GjdFlJz0hUXpQzn5hx5Nm+a3TmsRPgWw= X-Google-Smtp-Source: AH8x224rkqJkyQHHwfIQN1wwsAqYhtMuEjm0YfYaTv9xsyKm9A4DcNWYn4ik70+1E9pQNFRrn0rs+thMRmgol90Ldhg= X-Received: by 10.129.92.66 with SMTP id q63mr234740ywb.138.1518512407803; Tue, 13 Feb 2018 01:00:07 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.48.132 with HTTP; Tue, 13 Feb 2018 00:59:47 -0800 (PST) In-Reply-To: <1518511362343-0.post@n4.nabble.com> References: <1518018265328-0.post@n4.nabble.com> <1518086477724-0.post@n4.nabble.com> <1518511362343-0.post@n4.nabble.com> From: Romain Manni-Bucau Date: Tue, 13 Feb 2018 09:59:47 +0100 Message-ID: Subject: Re: JtaEntityManager GC To: users@tomee.apache.org Content-Type: multipart/alternative; boundary="001a114d46a2a77ac00565143875" --001a114d46a2a77ac00565143875 Content-Type: text/plain; charset="UTF-8" tomee closes the EM after the transaction, if you need to call clear() it means the close doesnt release the data in your provider - can be a bug. In terms of pattern you need to clear it when you don't need it anymore. A way to do it is a Synchronization and register it in the transaction synchronization registry - what we do by default. Now if you don't have any transaction it is after your last usage. The repo being not transactional and application scoped can justify a leak, if you put it request scoped (view scoped if you can) or @Transactional it should get fixed. Romain Manni-Bucau @rmannibucau | Blog | Old Blog | Github | LinkedIn | Book 2018-02-13 9:42 GMT+01:00 cocorossello : > Hi, > > Calling entityManager.clear() seems the best approach since most of the > queries are not executed inside a transaction. But I have no idea on where > I > should use it or what would be a good implementation pattern. > > I mean, let's say I have a @ViewScoped with a couple of injected > @ApplicationScoped. > > @ViewScoped > public class MyViewBean{ > > @Inject > private MyRepo1 myRepo1; > > @Inject > private MyRepo2 myRepo2; > > @PostConstruct > void init(){ > someVar1= myRepo1.loadSomeStuff(); > someVar2 = myRepo2.loadSomeStuff(); > } > .. > } > > @ApplicationScoped > public class MyRepo1{ > @PersistenceContext(unitName = "myUnit") > private EntityManager entityManager; > > public List loadSomeStuff(){ //Non transactional > entityManager.createQuery(....).getResultList(); > } > } > > } > > So, should I call entityManager.clear() after all non transactional queries > (or at least some of them)? Can I do it in some web filter? > > This seems pretty basic stuff but I can't get it right... > > > > -- > Sent from: http://tomee-openejb.979440.n4.nabble.com/TomEE-Users- > f979441.html > --001a114d46a2a77ac00565143875--