<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gerbrand on ICT &#187; jee</title>
	<atom:link href="http://www.gerbrand-ict.nl/tag/jee/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gerbrand-ict.nl</link>
	<description>Weblog on JEE and software-engineering</description>
	<lastBuildDate>Wed, 11 Aug 2010 20:51:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Whitebook on parallel programming</title>
		<link>http://www.gerbrand-ict.nl/2009/11/whitebook-on-parallel-programming/</link>
		<comments>http://www.gerbrand-ict.nl/2009/11/whitebook-on-parallel-programming/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 09:42:47 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jee]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=365</guid>
		<description><![CDATA[Via the newsletter of Whitehorses, the company I work for, an article written by me is published: Gebruik de multi-core omgeving met Java 7 . As the title suggest, the article is in Dutch. The article explains some of the new features of Java 7 for creating software that runs in parallel on multiple cores.]]></description>
			<content:encoded><![CDATA[<p>Via the newsletter of <a href="http://www.whitehorses.nl">Whitehorses</a>, the company I work for, an article written by me is published: <a href="http://www.whitehorses.nl/whitebooks/2009/gebruik-de-multi-core-omgeving-met-java-7">Gebruik de multi-core omgeving met Java 7 </a>. As the title suggest, the article is in Dutch. The article explains some of the new features of Java 7 for creating software that runs in parallel on multiple cores.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/11/whitebook-on-parallel-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JFall on Google Guice</title>
		<link>http://www.gerbrand-ict.nl/2009/09/google-guice/</link>
		<comments>http://www.gerbrand-ict.nl/2009/09/google-guice/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 12:47:55 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Various]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=358</guid>
		<description><![CDATA[Yesterday I&#8217;ve submitted a paper to NLJUG, the Dutch Java User Group for the JFall 2009 conference. Together with colleagues we worked on a proposal for a very nice presentation on the Google Guice. Like many programmers we were quite skeptical on yet-another Dependency Injection/IC framework. We all know Spring, and dependency injection is now [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I&#8217;ve submitted a paper to <a href="http://www.nljug.org/">NLJUG</a>, the Dutch Java User Group for the <a href="http://www.nljug.org/pages/events/content/jfall_2009/">JFall 2009</a> conference. Together with colleagues we worked on a proposal for a very nice presentation on the <a href="http://code.google.com/p/google-guice/">Google Guice</a>. Like many programmers we were quite skeptical on yet-another <a href="http://en.wikipedia.org/wiki/Inversion_of_control">Dependency Injection</a>/IC framework. We all know Spring, and dependency injection is now also part of the J2EE 1.5 / EJB3 standard. What makes Guice worth looking at?<br />
In our talk we&#8217;ll explain (of course) what Google Guice is, and how Guice compares to Spring and EJB3. Hope to see you on JFall!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/09/google-guice/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Threads-alternative in JEE: using the timerservice</title>
		<link>http://www.gerbrand-ict.nl/2009/04/threads-alternative-in-jee-using-the-timerservice/</link>
		<comments>http://www.gerbrand-ict.nl/2009/04/threads-alternative-in-jee-using-the-timerservice/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 15:14:46 +0000</pubDate>
		<dc:creator>gerbrand</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[jee]]></category>

		<guid isPermaLink="false">http://www.gerbrand-ict.nl/?p=171</guid>
		<description><![CDATA[A common problem in in developing Java Enterprise (JEE or J2EE) application is working with threads, or more generally executing code asynchronously. Starting and instantiating threads in the old-fashioned java way is not allowed. The reason: within JEE you work with EJB&#8217;s: Java Beans with managed resources. Databaseconnections, transactions, sessions, all of these resources are [...]]]></description>
			<content:encoded><![CDATA[<p>A common problem in in developing Java Enterprise (JEE or J2EE) application is working with threads, or more generally executing code asynchronously. Starting and instantiating threads in the old-fashioned java way is not allowed.<br />
The reason: within JEE you work with EJB&#8217;s: Java Beans with managed resources. Databaseconnections, transactions, sessions, all of these resources are managed by the application server. Usually resources such as databaseconnections are not thread-safe. The application server will take of any issues related to thread-safefety, as long as you don&#8217;t instantiate threads yourself. That being said, <em><strong>what is the JEE-alternative to using threads</strong></em>?</p>
<p>There are several possible answers to that question:</p>
<ul>
<li>Using a JMS, Java Messing Service. How to setup is beyond the scope of this weblog posting.</li>
<li>Use of the Timerservice. The timerservice is part of JEE-spec (since 1.4). Using a few annotations you can have the same functionality as you would have when using threads &#8211; but compliant with the JEE-spec. I&#8217;ll explain how to use the TimerService, so you can stop worrying about not being JEE compliant (with regard to threads)!</li>
</ul>
<p>The <a href="http://java.sun.com/javaee/5/docs/api/javax/ejb/TimerService.html">TimerService </a>can only be used within a stateless EJB bean. So to start you&#8217;ll have to define one, by adding the right annotations:</p>
<pre class="brush: java;">..

@Stateless
public class MyTimerExampleBean implements MyTimerExample {

}
...
public interface MyTimerExample {
}</pre>
<p>Within the bean you can inject the timerservice using the Resource annotation. As soon as the bean is deployed within an application server like JBoss, the bean is instantiated and the resources are injected and available for use.</p>
<pre class="brush: java;">    @Resource
    private TimerService timerService;</pre>
<p>Now we&#8217;ll use our timerservice. We define a method called <em>startMe </em>and a method <em>runMe</em>. The startMe method will define a timer. The timer will then execute the runMe method after a predefined time.</p>
<p>When the <em>runMe </em>method is to be executed, the bean is newly instantiated. This means, if you set any local variables within your bean, those values will be lost. For that reason, we use the <em><strong>myInfo </strong></em>class to transfer parameters, in this case a delay and the message we want to print to the screen.</p>
<pre class="brush: java;">class HelloWorldInfo implements Serializable {
   String message;
   long delay;
   int counter;
}
public void startMe() {
    long waitTime =60*1000; //60 seconds, 1 minute
    HelloWorldInfo taskInformation=new HelloWorldInfo();
   taskInformation.message="Hello world";
   taskInformation.delay=12*1000; //12 seconds
   taskInformation.counter=0;

   Timer timer = timerService.createTimer(waitTime, taskInformation);

}
    @Timeout
    public synchronized void runMe(Timer timer) {

      final HelloWorldInfo myInfo = (HelloWorldInfo ) timer.getInfo();

      System.out.println("Going to do something important");
      Thread.wait(5000);
      System.out.println(myInfo.delay);
      System.out.println(myInfo.message);
  }</pre>
<p>That&#8217;s all there is! Using the above code, will allow you to run code asynchronously in a similar fashion when using Thread and Runnable classes. You could for example call a remote webservice, or run a batch job on the database. The method runMe will run within a separate transaction &#8211; in case an error is thrown within the the runMe method, the transaction is rolled back. Since the bean is instantiated using the JEE-container, any resources associated with the bean will be discarded.</p>
<p>If you want want to execute the run method again, the easiest way is to call the startMe method again:</p>
<pre class="brush: java;">   public synchronized void runMe(Timer timer) {
     ...

   myInfo.counter++;
   myInfo.message="Doing hello world again for the "+myInfo.counter;
   myInfo.delay=6*1000; //now after 6 seconds

   Timer timer = timerService.createTimer(waitTime , myInfo
);
  }</pre>
<p>The myInfo is modified and passed again to the timerserver. So next time the bean is instantiated and the run method is executed, it&#8217;ll display &#8216;Doing hello world again 1&#8242;, and will do so with an incrementing number until the application server is shut down. You can pass any information on, as long as the the class containing the information is serializable.</p>
<hr />
<table width='100%'>
<tr>
<td>
<iframe src="http://rcm.amazon.com/e/cm?t=geonic-20&#038;o=1&#038;p=8&#038;l=as1&#038;asins=1933988029&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;m=amazon&#038;lc1=0000FF&#038;bc1=000000&#038;bg1=FFFFFF&#038;f=ifr&#038;nou=1" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
</td>
<td border='1' align='right'><strong>Bol.com</strong><br/><br />
<A HREF="http://clk.tradedoubler.com/click?a=1601917&#038;p=67859&#038;g=17297702&#038;epi=1001004005604637" TARGET="_BLANK"><IMG SRC="http://www.bol.com/imgbase0/thumb/BOOKCOVER/FC/1/9/3/3/9/1933988029.gif" ALT="Jboss in Action" BORDER="0"><BR>Jboss in Action<BR>Javid Jamae &#038; Peter Johnson<BR></A>
 </td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.gerbrand-ict.nl/2009/04/threads-alternative-in-jee-using-the-timerservice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
