Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I/O operations in beans

0 views
Skip to first unread message

Bernhard

unread,
Oct 17, 2002, 5:08:46 AM10/17/02
to
I asked this before, but I've got no response for that thread. Now I try it
again, maybe someone can make a comment about this.

How are the restrictions about I/O operations in a bean?

I have to access a file out of a session bean.
Is that allowed?
Is there a good way to do this?

Regards

Jens Kutschke

unread,
Oct 17, 2002, 7:47:50 AM10/17/02
to
>
> How are the restrictions about I/O operations in a bean?
>
> I have to access a file out of a session bean.
> Is that allowed?
> Is there a good way to do this?
>

Hi,

take a look at the EJB-specifications 2.1:

"An enterprise bean must not use the java.io package to attempt to access
files and directories in the file system."

It is not allowed to access files. EJB is a multithreaded environment!

Bye,
Jens

--
_____________________________________________
Jens Kutschke
http://www.j-dimension.com


Chris

unread,
Oct 17, 2002, 10:32:09 AM10/17/02
to
"Bernhard" <Bernhard....@t-system.com> wrote in message news:<aolug7$93b$1...@news.sns-felb.debis.de>...

I believe the ejb spec does not allow java.io operations. However, I
would try to wrap all your logic inside a regular bean & use that bean
inside an ejb bean. ( never tried that but don't see why it wouldn't
work ) ... can anybody tell me if i'm way off base here?

Bengt Bäverman

unread,
Oct 17, 2002, 1:27:08 PM10/17/02
to
I don't understand how pushing the use of i/o down one level suddenly makes
it legal. If you are not allowed to do i/o operations in an EJB, then you
are not allowed to do i/o operations in an ejb, even if you ask another
class to do it.

The reason, I believe, is that doing i/o operations can take some
(undetermined) time to complete, and that could potentially make your bean
hang during these operations. You would want to avoid this.

/Bengt B


"Chris" <cbrou...@liquiddatainc.com> wrote in message
news:89b6b185.02101...@posting.google.com...

Jens Kutschke

unread,
Oct 18, 2002, 2:29:23 AM10/18/02
to

> I don't understand how pushing the use of i/o down one level suddenly
makes
> it legal. If you are not allowed to do i/o operations in an EJB, then you
> are not allowed to do i/o operations in an ejb, even if you ask another
> class to do it.
>
> The reason, I believe, is that doing i/o operations can take some
> (undetermined) time to complete, and that could potentially make your bean
> hang during these operations. You would want to avoid this.
>

You're right. Putting all the I/O in separate classes outside the EJB does
not solve the problem.
I've read that the only way to do this is to do the I/O in another VM. But
maybe there are other
solutions...

Rob Seegel

unread,
Oct 21, 2002, 9:26:22 AM10/21/02
to
>I have to access a file out of a session bean.

Do you need to write to the file? You might be able to use JMS to send a
message to another component that handles the writing for you.

Rob

Bengt Bäverman

unread,
Oct 21, 2002, 1:57:27 PM10/21/02
to
Would it be more legal to do i/o in a message bean than in an entity or
session bean?
I don't think so. Am I wrong?

/Bengt B

"Rob Seegel" <robs...@aol.com> wrote in message
news:20021021092622...@mb-fy.aol.com...

Rob Seegel

unread,
Oct 21, 2002, 9:28:41 PM10/21/02
to
>Would it be more legal to do i/o in a message bean than in an entity or
>session bean?
>I don't think so. Am I wrong?

I wasn't really even talking about a message bean, but some separate server
component outside of the bean container that could handle the queued messages
in whatever manner made sense. If that happened to be writing to the
filesystem, then so be it, but as an answer to your question, no -- just
because it is a message driven bean doesn't mean that the rules can be ignored.

What is the specific problem you are trying to solve by using the filesystem?
You don't get transactions with filesystems, and another big drawback is that
you can't portably depend on a filesystem structure.

Rob


Raymond Decampo

unread,
Oct 25, 2002, 7:18:18 PM10/25/02
to
Jens Kutschke wrote:
>>How are the restrictions about I/O operations in a bean?
>>
>>I have to access a file out of a session bean.
>>Is that allowed?
>>Is there a good way to do this?
>>
>
>
> Hi,
>
> take a look at the EJB-specifications 2.1:
>
> "An enterprise bean must not use the java.io package to attempt to access
> files and directories in the file system."
>
> It is not allowed to access files. EJB is a multithreaded environment!
>

Does anybody know if this restriction applies to URLs as well? It seems
the spec allows you to have a client socket so you would be OK accessing
another server. On the other hand, some URLs point to the file system.
For example, is it legal to use ResourceBundle.getBundle() or
ClassLoader.getResource() when the resulting URL points to the local
file system?

Ray

Jeff

unread,
Oct 27, 2002, 1:02:07 AM10/27/02
to

> > >I have to access a file out of a session bean.
> >
> > Do you need to write to the file? You might be able to use JMS to send a
> > message to another component that handles the writing for you.

One fairly straightforward approach is to use a Singleton to initialize and
wrap access to the file. Assuming you are only operating on one file and
that makes sense for your use case, it's safe in the EJB environment.

Jeff
Technical Lead
eBay, Inc.

--
eBay is recruiting for multiple open Java positions.
Email me your resume to be put in contact with
a hiring manager. Principles only.


0 new messages