Adam Bien's Weblog

Tuesday Feb 09, 2010

Simplest Possible EJB 3.1 Timer


@Singleton
public class TimerService {
    @EJB
    HelloService helloService;
  
    @Schedule(second="*/1", minute="*",hour="*", persistent=false)
    public void doWork(){
        System.out.println("timer: " + helloService.sayHello());
    }
}

A timer doesn't have to be a singleton - it can be a @Stateless and even a @Stateful bean. The method doWork() will be invoked every second. There is no registration or configuration needed.

How to compile:

You will need the EJB 3.1 API in the classpath, or at least the @Singleton, @Schedule and @EJB annotation.

How to deploy:

Just JAR or WAR the interceptor with an EJB and put the archive into e.g: [glassfishv3]\glassfish\domains\domain1\autodeploy

Btw. the initial deployment of the entire WAR took on my machine:


INFO: Loading application SimpleTimer at /SimpleTimer
INFO: SimpleTimer was successfully deployed in 363 milliseconds.

How to use:

Another service can be easily injected to the timer and so invoked periodically:

@Stateless
public class HelloService {
    public String sayHello(){
        return "Hello from control: " + System.currentTimeMillis();
    }
}

And: there is no XML, strange configuration, libraries, additional dependencies needed...You will find the whole executable project (tested with Netbeans 6.8 and Glassfish v3) in: http://kenai.com/projects/javaee-patterns/ [project name: SimpleTimer].

[See also "Real World Java EE Patterns - Rethinking Best Practices"] 


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Sunday Feb 07, 2010

bad pbr sig - and a simple solution

After the addition of a hard disc to a mirrored zfs rpool, the boot process immediately stopped with the GRUB message: "bad pbr sig". It means that something is wrong with the Primary Boot Record (aka Master Boot Record). The solution was simple - I swapped the boot order of the hard discs in BIOS. Now it works perfectly again.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Saturday Feb 06, 2010

kenai.com is dead - long live kenai (under different name)

Even got this email: 

"In an effort to get information out to the Kenai community quickly, while trying to manage the integration of our two companies, I think we did a poor job at communicating our plans for Kenai.com to you.  I would like to remedy that now.  Our strategy is simple.  We don't believe it makes sense to continue investing in multiple hosted development sites that are basically doing the same thing.  Our plan is to shut down kenai.com and focus our efforts on java.net as the hosted development community.  We are in the process of migrating java.net to the kenai technology.  This means that any project currently hosted on kenai.com will be able to continue as you are on java.net.  We are still working out the technical details, but the goal is to make this migration as seamless as possible for the current kenai.com projects.  So in the meantime I suggest that you stay put on kenai.com and let us work through the details and get back to you later this month. 

Thanks for your feedback and patience."

These are actually great news. Hopefully all the kenai.com infrastructure like mercurial (subversion isn't fun), jira and hudson will be supported by java.net. So I'm waiting with the migration of "Real World Java EE Patterns" project and will even commit some more content soon. The great story about mercurial: the whole repository with history etc. sits on my machine and can be pushed wherever I want :-). kenai.com is/was an interesting platform - suitable not only for opensource projects.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Tuesday Feb 02, 2010

Object Pooling Can Be Still Useful - For Entirely Different Reasons

Pooling was initially introduced as a tuning action for the slow performance of object creation and garbage collection in particular. On a modern JVM > 1.4 pooling is no more needed for the optimization of memory management in a typical business application. It can even have a negative effect on the garbage collector performance. In special cases, like creating millions of instances in every method call, it could still pay off. 

Instance pooling, however is still interesting for objects with slow custom "post construction". In some cases you want to inject some dependencies after the object creation, read some configuration etc. This can be slow and doesn't have to be performed over and over again. In such cases object pooling will improve the overall performance. 

Instead of prematurely optimize your application, I would rather build the simplest possible thing and measure the performance continuously (e.g. with VisualVM). In most cases you will be surprised where the actual bottlenecks actually are. 


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Saturday Jan 30, 2010

Free JUG Session In Hamburg - Real World Java EE Patterns - Rethinking Best Practices

At 02.02.2010, 8 P.M. I'm going to give a free JUG talk about Java EE 6 / 5 cool stuff and best practices in Hamburg.
We will discuss the relation between Contexts and Dependency Injection (CDI / JSR-299), Dependency Injection for Java (JSR-330) and EJB 3.1 - the lightweight components :-) Also the new Java EE 6 stuff like: stereotypes, interceptors, decorators, validation, REST + EJB 3.1 are going to be covered.
The Java EE 6 impact on architecture, build and test will be discussed as well. Heretical questions are especially welcome - this is a JUG session so it should be interactive fun.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Thursday Jan 28, 2010

Sun + Oracle, NetBeans, Glassfish, JavaOne and the Death of Kenai

JavaOne will take place in San Francisco from September 19-23, 2010 - so I was semi right :-). Most of the questions are answered here. kenai.com will be killed. What is a pity - it is/was a great platform with mercurial support. Glassfish, however, will be also commercially supported by Sun/Oracle.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Wednesday Jan 27, 2010

JDeveloper vs. NetBeans - The Poll Results

The results are amazing: 434 (NetBeans) vs. 18 (JDeveloper). JDeveloper comes with some interesting stuff - it would be a nice extension of NetBeans. The integration wouldn't be that hard - both IDEs are Swing based...


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Friday Jan 22, 2010

Sun + Oracle = Snorcle?

The new Sun + Oracle logo was revealed. Somehow aquarium / oracun and sparky related :-)


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Thursday Jan 21, 2010

Sun And Oracle - The Deal Is Approved

Some details. Hopefully the strategic plans / roadmap regarding Glassfish, NetBeans, OpenSolaris and hardware will be revealed soon. ...and what about JavaOne? :-)


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

My Opinion About Java FX

I was interviewed (java.sun.com) about Java FX in the enterprise, Java FX tooling and superfluous GoF patterns.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Interviews/About
My Recent Book
Java One 2009
CommunityOne East N.Y.C
JavaONE 2008 Interview
Search
...the last 150 posts
...the last 10 comments
greenfire.dev.java.net
Links
my.netbeans.org
Visitors
License