Hi all Can anybody tell me , whether file writing is possible in EJB or not? Because as per the specification it is mentioned that its not a good practice. In that case if i want to log an error from the bean what would be that best way? Also i have one requirement for creating a file at runtime. For that if i choose bean, will it create any problem ? or tell me its possible.. Thanks george
Joined: Dec 09, 2000
Hi george, File Input/Output are not advisable as per EJB specs, though you can do it, no one stops you from reading from a file or any IO operations.Things may go hunky-dory when then network connections opened by you (if it) clashes with that opened by the container.you should be very careful to study how the container manages the IO operations before doing it programatically. As regards creating a file at runtime, I think it should be encapsulated in a JavaBean or a helper class and not a EnterpriseBean and if required you can call a normal bean from a EJB (put the Java Bean reference entry into <ejb-ref> and map the same). Bye Rishi Singh SCJP,SCWCD
Although doing file I/O in an EJB probably won't cause you to crash and burn, it won't win you any prizes, either. Sun lists a number of reasons why it's a Bad Thing in the EJB spec. A good way to look at an EJB method is to consider an EJB to be rather like a Windows DLL. It's something you call rather than something that does work on its own, and you should furthermore keep the work done in a call to be short and fast. However, in a DLL, the methods can spawn threads to maintain state and do background processing. EJBs aren't allowed to do this. So if you need "heavy lifting", do it in a servlet or a task service outside the EJB.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Apr 22, 2001
If you would like to write files or log from enterprise beans use Message Driven Bean wich reads the que and write to file so do some JMS from the client and it should be fine