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
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
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?
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...
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...
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
"Rob Seegel" <robs...@aol.com> wrote in message
news:20021021092622...@mb-fy.aol.com...
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
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
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.