main website home
  • About this blog

    This blog features updates, opinions, and technical notes from Caucho engineers about Caucho products, the enterprise Java industry, and PHP. Caucho Technology is the creator of the Resin Application Server and the Quercus PHP in Java engine. A leader in Java performance since 1998, Caucho is a Sun JavaEE licensee with over 9000 customers worldwide.
  • Tags

    ajaxworld bam candi cdi cloud cluster comet configuration deploy devoxx eclipse ejb embedded flash flex google app engine hessian hmtp ioc java ee 6 javaone javazone jms messaging newsletter nyjug osgi php pomegranate quercus resin resin 4.0 REST servlet sfjug silicon valley code camp spring testing training tssjs watchdog webbeans web profile websockets wordpress
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
« Networking modularity for testing
@PooledBean attributes »

@PooledBean

As we’re working on passing the EJB TCK for JavaEE 6 WebProfile, we’ve also been talking about how to improve EJB further for JavaEE 7. One idea that we’ve discussed is creating a @PooledBean lifecycle.

The @PooledBean would streamline, simplify, and improve the robustness of the current @Stateless bean, which fits nicely into our goals of improving performance and robustness of the WebProfile.

The purpose of the @PooledBean is to clean up the boilerplace try finally code used for long-lived resources like JDBC, JPA, sockets,
and JMS. The @PooledBean treats the allocation and freeing of the resources as cross-cutting concerns, handled by the @PostConstruct and @PreDestroy methods.

As code, the @PooledBean is a class annotation that would tell the application server to pool instances of the bean on all interface method invocations. In all other ways, the class would remain a plain CDI managed bean: no special context object, no special classloader behavior, no jndi, and no extra transaction defaults. Just the pooling capability. The code might look like:

package com.example;

import com.caucho.inject.PooledBean;

@PooledBean
public class MyPooledBean implements PooledApi {
  private ExpensiveResource = _resource;

  String hello()
  {
     return _resource.doHelloMethod();
  }

  @PostConstruct
  void init()
  {
     // allocate expensive resource
  }

  @PreDestroy
  void destroy()
  {
     // free expensive resource
  }
}

Since the destroy() code is guaranteed to be called when the instance is destroyed, your finally code can be shared by all the business methods. Even better, you can put the init()/destroy() code in a common superclass. From a testing point of view, this change makes the application more reliable, because you can fully test the resource close for every method without creating separate tests for separate finally blocks.

This entry was posted on Monday, May 17th, 2010 at 12:51 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Responses to “@PooledBean”

  1. stickfigure Says:
    May 17th, 2010 at 4:26 pm

    This is a great great great idea… especially with some way to control the max pool size.

  2. ferg Says:
    May 17th, 2010 at 7:07 pm

    Good point. Tomorrow, I can put up the pool size attributes we’ve talked about internally.

  3. stickfigure Says:
    May 21st, 2010 at 11:18 am

    Just a thought but… why not call it @Pooled instead of @PooledBean? It would fit better into the conventions of other EE annotations, @Stateless, @Stateful, @MessageDriven, etc.

  4. ferg Says:
    May 25th, 2010 at 10:39 am

    Good point. @Pooled is a better name.

Leave a Reply

You must be logged in to post a comment.


Caucho Technology is proudly powered by WordPress and Quercus®
Entries (RSS) and Comments (RSS).

  • HOME |
  • CONTACT US |
  • DOCUMENTATION |
  • BLOG |
  • WIKI 4 |
  • WIKI 3 |
  • Resin: Java Application Server
Copyright (c) 1998-2012 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.
resin® is a cloud optimized, java® application server that supports the java ee webprofile ®