Well, its that time again. Time to work on the next version of Java EE and that means EJB 3.1. Since the EJB 3.1 list is a private one, I intend to regularly converse with the community through this blog to tell you what’s going on and to obtain valuable feedback.

One new thing that is being circulated in the expert group is the idea of a singleton EJB much like what we already provide in JBoss EJB 3.0 implementation through @Service beans. Singleton EJBs would be a single EJB instance, created at boot-time, with the same functionality as stateless and stateful beans (remote, local, and web service interface, transactions, security, injection ,etc…)

Singletons and concurrency

There’s a couple of debates going on within the expert group on singletons and their concurrency with multiple invocations. Should only single-threaded singletons be allowed? Since servlets can either ben single or multi-threaded, seems reasonable to allow the same thing in EJB land. But, what do you think? If we support both models, what should be the default? Again, your feedback is needed!

Convenient concurrency

Another idea being proposed is to expand the concurrency model even further and provide convenience annotations over the java.util.concurrent library, for instance

@Singleton
public class MyBean {
   @ReadOnly public int getStuff() {...}
    @Write public void setStuff(int i) {...}
}

Basically the @ReadOnly and @Write annotations would manage a read-write lock that is implicitly associated with the single instance and managed by the EJB container.

So, if we’re gonna do basic concurrency, what about transactional concurrency as well? Should read/write locks be transactional as well? Held for the duration of a transaction?

If all this is gonna happen, how do we declare the default concurrency? Here’s one idea:

enum ConcurrencyMode {
   SINGLE_THREADED,
   MULTI_THREADED,
   READ_WRITE,  // use a readwritelock, but read is the default access if no annotation provided
   WRITE_READ, // use a readwriteock, but write is the default access if no annotation is provided
   TRANSACTIONAL_READ_WRITE, // same as READ_WRITE but transactional
   TRANSACTION_WRITE_READ // same as WRITE_READ but transactional
}

@Singleton(concurrency=WRITE_READ)
public class myBean {...}

Feedback needed

Any feedback in the comments section of this blog. Even a simple +1 or -1, or +1 on @Singleton, -1 on concurrency are all valuable feedback!