• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread and File IO question

 
Paul Lj
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a question relating to thread and File IO in an EJB.
Is an EJB allowed to call a method on another object that performs either File IO or threading ?
e.g. assume the following simple session bean :
public class SimpleBean implements SessionBean {
// bean methods removed
public void someBusMethod() {
// call another object with a method that does file io
someOtherObject.methodWithFileIO();
// similarly - an object that does threading
anotherObject.methodWithThreading();
}
}
Are these method calls valid ? What if your bean called a 3rd party library that performs threading / file io and you weren't aware of it - Is your bean still "legal" ?

Thanks in advance
Paul
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spec C.1.2, pg 538:
An enterprise bean must not use the java.io package to
attempt to access files and directories in the file system.

and pg 539:
The enterprise bean must not attempt to manage threads.

The first limitation is easy to get around, there are JNDI filesystem providers that give you access to the filesystem. The issue isn't that you can't access files, just that you need to use a J2EE-portable way of doing it (this isn't an issue for the exam, but how you deal with the problem in real projects).
The second issue is particulary important. Spawning threads in an EJB container is a BAD THING. It mucks up transaction handling, can lock up container resources, is a slow resource leak (because of how the JVM gets threads from the O/S without ever releasing them) and can drag down container performance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic