0

Is there a JDK 5 or older API for reading files and or reading streams with a timeout? Also, this API must be safe when wrapped inside an MDB. FYI: I have already looked into using the FutureResult, TimedCallable classes and the like; I have come to the conclusion that using these within in MDB is not advisable since 1. these are not JDK native classes, and 2. threads are spawned inside the MDB; so I need another solution.

Also I would believe that any solution would require threading since there must be a thread that reads and one that manages the the timeliness of the read thread and blocks it if necessary. Therefore, would such a behavior be illegal inside an MDB? What if said API is native to the JDK will this make it safe to implement?

MaDa
  • 10,511
  • 9
  • 46
  • 84
TheWolf
  • 1,675
  • 4
  • 22
  • 34

1 Answers1

1

As you see from the InputStream API there is no general contract for this. However some Streams, like the InputStream you get from a socket, have a timeout behaviour, but this has to be configured on the socket.

AFAIK you can try to interrupt the reading Thread manually, by calling interrupt() on it, and hope that the underlying implementation of your Stream does not catch this without rethrowing it (A common mistake when using wait() on a monitor). This however has to be done in an extra thread, or by using the Future API you mentioned above. If you catch this InterruptedException, and handle it appropriately, you should have a fairly stable solution.

PS: What is an MDB? I only know this acronym for the Microsoft Database format used by Microsoft Access.

Daniel
  • 27,718
  • 20
  • 89
  • 133
  • Thanks, an MDB is a Message Driven Bean a type of EJB (Enterprise Java Bean) which handles asynchronous communication. It is used as a wrapper for business logic to be triggered by asynchronous messages. In an MDB however and in any J2EE container it is illegal to spawn threads as it may interfere with the EJB's life-cycle; so I was looking for a JDK native API that would handle the threading internally. – TheWolf Dec 30 '10 at 17:10
  • Please unvote me... I just need one question unvoted for my unsung hero :))!! – Daniel Feb 04 '11 at 19:34